2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【ActiveModelのクラスを読み込めない】 uninitialized constant Tweet::ActiveModel (NameError)

2
Last updated at Posted at 2019-01-25

はじめてActiveModelを使おうと思って、とりあえずモデルファイルを作成。
(putsは読み込めているか確かめようと思い書いてみた)

class Tweet
  include ActiveModel::Model
  puts "hello"
end

エラー

コマンドプロントで読み込んでみるも失敗。読み込めていなかった

Traceback (most recent call last):
        1: from tweet.rb:1:in `<main>'
tweet.rb:2:in `<class:Tweet>': uninitialized constant Tweet::ActiveModel (NameError)

対策

このサイトの通りにreauire 'active_model'と追加してみた。

You have to require the whole of active_model since it uses autoload to "lazily require" classes as needed.
The following code works fine:

require 'active_model'


class Person
  include ActiveModel::Validations
end

結果

$ ruby tweet.rb
=> hello

成功かな

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?