2
乾草同胞開發商選擇,錯CLASS_NAME通過ActiveRecord的
當我調用@ chapter.articles,導軌產生以下錯誤:
uninitialized constant Sommaire::Chapter::Article
事件如果我指定:CLASS_NAME =>「Sommaire ::文章」, 它產生:
uninitialized constant Sommaire::Chapter::Sommaire::Article
由於我比較NE w到rails(3.0.0),這已經讓我失望了!
在此先感謝您的幫助。 JD
下面的代碼從類
在sommaire.rb
class Sommaire < ActiveRecord::Base
has_many :chapters
end
在sommaire/chapter.rb
class Sommaire::Chapter < ActiveRecord::Base
include ItemBase
def self.table_name
'sommaire_chapters'
end
belongs_to :sommaire
has_many :articles, :class_name => "Sommaire::Article"
validates_presence_of :title, :description
end
在sommaire /條。 rb
class Sommaire::Article < ActiveRecord::Base
include ItemBase
def self.table_name
'sommaire_articles'
end
belongs_to :chapter
end
偉大的長老們的智慧再一次啓發了我。 (我也會考慮重命名「Sommaire」僞命名空間) – 2010-08-24 11:26:44