Ruby on rails Rails中未正确加载抽象类

Ruby on rails Rails中未正确加载抽象类,ruby-on-rails,ruby-on-rails-3,abstract-class,eager-loading,Ruby On Rails,Ruby On Rails 3,Abstract Class,Eager Loading,这是我的类层次结构: 在我的项目模型中,我有如下内容: class Item < ActiveRecord::Base TYPES = [Weapon::TYPES, Armour::TYPES, Misc::TYPES].flatten.freeze end 如果我删除它,那么我可以运行控制台 另一件奇怪的事: $ rails c > WEAPON > NameError: uninitialized constant Weapon #why is it l

这是我的类层次结构:

在我的
项目
模型中,我有如下内容:

class Item < ActiveRecord::Base
    TYPES = [Weapon::TYPES, Armour::TYPES, Misc::TYPES].flatten.freeze
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>'
$rails c
>武器
>NameError:未初始化的常量武器#为什么要查找该类??
>from/Users/hello\u so/localhost/search/app/models/item.rb:7:in`'

但是如果我加载了
Item
(通过键入
Item
),那么它会抱怨武器常数。

您是否尝试包含您的抽象类:
require Rails.root+path

在哪里定义了
Misc
?如果你这样做怎么办?
::Misc::TYPES
?Misc在models/Misc.rb中,与武器和装甲完全相同。我试过::Misc.It只是Misc,如果它在models/Misc.rb中的话,而不是awesome图表上的Item::Misc.Kudos+仅此一项。@Intelekshual好吧,它抱怨Item::Misc,因为出于某种原因,它找不到Misc类。。。如果我使用::Misc,那么它会抱怨Misc。顺便说一下,当我从Item类中删除Misc::TYPES和BASE_名称时,我可以启动控制台。。。我不知道它们之间有什么区别。请注意,
Rails.root
是一个
Pathname
,而不是
String
Pathname
+
操作符是不同的<代码>路径应该是相对路径,而不仅仅是要附加的字符串。特别是,不要以
/
开头,因为这将被解释为“从文件系统的根开始”,并且
Rails.root的值将被抛出。
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>'