Monologue という Rails ブログ エンジンを使用しています。エンジンのモデルの 1 つに、メインのアプリ モデルとの belongs_to および has_many 関係を持たせたいと考えています。ユーザー (作成者) は多くの投稿を持つことができ、投稿は作成者 (ユーザー モデル) に属します。class_name でモデルの名前空間を指定しようとしましたが、まだエンジン内でモデルを検索しています。
エラー
NameError: uninitialized constant Monologue::Post::MyApp::User
post.rb
class Monologue::Post < ActiveRecord::Base
belongs_to :author, :class_name => "MyApp::User", :foreign_key => "author_id"
end
user.rb
class User < ActiveRecord::Base
has_many :posts, :class_name => "Monologue::Post", :foreign_key => "author_id"
end
スキーマ
create_table "monologue_posts", force: true do |t|
t.integer "author_id"
end