2

やあ、仲間の開発者、

@chapter.articlesを呼び出すと、Rails で次のエラーが発生します。

uninitialized constant Sommaire::Chapter::Article

:class_name => "Sommaire::Article"を指定すると、次のようになります。

uninitialized constant Sommaire::Chapter::Sommaire::Article

私はレール(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/article.rb

class Sommaire::Article < ActiveRecord::Base

  include ItemBase

  def self.table_name
    'sommaire_articles'
  end

  belongs_to :chapter

end
4

1 に答える 1

3

Sommaire パスがルート名前空間からのものであることを示すことは、試してみる価値がありますclass_name => '::Sommaire::Article'(前述の注意)。::

Sommaireただし、名前空間とモデルの間で競合が発生する可能性がありSommaireます。その場合、どちらか一方の名前を変更する必要があります。

于 2010-08-24T10:16:51.457 に答える