我定义了三个类,如下所示:
class Animal < ActiveRecord::Base
attr_accessible :animal_definition_id, :aquarium_id
belongs_to :animal_definition
belongs_to :aquarium
has_many :comments, as: :commentable
end
class Fish < Animal
end
class Coral < Animal
end
如果我启动控制台并输入:
Coral.all
我得到:
NameError: uninitialized constant Coral
from (irb):1
from /Users/gjr/.rvm/gems/ruby-1.9.3-p125@WebDev/gems/railties-3.2.10/lib/rails/commands/console.rb:47:in `start'
from /Users/gjr/.rvm/gems/ruby-1.9.3-p125@WebDev/gems/railties-3.2.10/lib/rails/commands/console.rb:8:in `start'
from /Users/gjr/.rvm/gems/ruby-1.9.3-p125@WebDev/gems/railties-3.2.10/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
现在......如果我输入Animal.all
它按预期工作。然后Coral.all
工作正常!
为什么在珊瑚工作之前需要引用动物?顺便说一句,如果我做的事情不是all
. Coral.class
做同样的事情。
我还没有在我的实际应用程序中看到这种行为,但我担心它是一个等待发生的奇怪错误。
谢谢!