2010-08-24 31 views
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 

回答

3

這將是值得嘗試class_name => '::Sommaire::Article'(注前::),表明Sommaire路徑是從根名稱空間。

雖然有一個Sommaire命名空間和Sommaire模型之間有一些衝突,在這種情況下,您可能想要重命名一個或另一個。

+0

偉大的長老們的智慧再一次啓發了我。 (我也會考慮重命名「Sommaire」僞命名空間) – 2010-08-24 11:26:44

相關問題