다음과 같이 나는 세 가지 클래스 정의 : 나는 콘솔 입력 불 경우단일 테이블 상속을 알 수없는 하위 클래스
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
같은 일을합니다.
실제 응용 프로그램에서이 동작을 보지 못했지만 이상한 버그가 발생하기를 기다리고 있습니다.
감사합니다.