2012-03-22 23 views
0

私はRails 3.2を使用しています。私は特定のブログのコメント欄のリストが欲しいブログのコメント作成方法を教えてください

Blog 
Comment 
User 

class Blog < ActiveRecord::Base 
    has_many :comments 
end 

は、私は次のモデルを持っています。

は、私は、ユーザーインスタンスの配列を返す必要があり

class Blog < ActiveRecord::Base 
     has_many :comments 
     has_many :commenters, ...fill in the blank... 
    end 

@blog.commentersような何かをしたいです。

上記の空白はどうすればよいですか。

答えて

1

私はあなたが追加する必要があるすべては

class Blog 
    has_many :commenters, :through => :comments, :source => :user 
end 

注意であるあなたは、次の

class User 
    has_many :comments 
end 

class Comment 
    belongs_to :blog 
    belongs_to :user 
end 

class Blog 
    has_many :comments 
end 

を持っていると思います:comments上の関係がcommenters

と呼ばれていないため、 :sourceが必要とされています
関連する問題