3
我有三個類定義如下:單個表繼承子類未知
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/[email protected]/gems/railties-3.2.10/lib/rails/commands/console.rb:47:in `start'
from /Users/gjr/.rvm/gems/[email protected]/gems/railties-3.2.10/lib/rails/commands/console.rb:8:in `start'
from /Users/gjr/.rvm/gems/[email protected]/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
做同樣的事情。
我在實際的應用程序中沒有看到這種行爲,但我擔心它會發生一個奇怪的錯誤。
謝謝!