これが私のクラス階層です:
私のItem
モデルでは、次のようなものがあります。
class Item < ActiveRecord::Base
TYPES = [Weapon::TYPES, Armour::TYPES, Misc::TYPES].flatten.freeze
end
そして、抽象クラスは次の形式です。
class Misc < Item
self.abstract_class = true
TYPES = G_BASE_NAMES["misc"].keys.freeze
end
コンソールを起動すると、次のようになります。
/Users/hello_so/localhost/search/app/models/item.rb:7:in `': 初期化されていない定数 Item::Misc
item.rb の 7 行目がそのTYPES = ...
行です。
武器や防具ではなくその他について文句を言うのはなぜですか? (ところで、ファイルの最初に表示されます)?
編集:私は実際に初期化子でそれを行っていました(問題を修正するために最近追加したもの)
if Rails.env.development?
Dir[Rails.root + 'app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
end
削除すると、コンソールを実行できます。
別の奇妙なこと:
$ rails c
> WEAPON
> NameError: uninitialized constant Weapon #why is it looking for the class??
> from /Users/hello_so/localhost/search/app/models/item.rb:7:in `<class:Item>'
Item
しかし、 ( と入力して)ロードItem
すると、WEAPON 定数について不平を言うでしょう。