0

acts_as_commentable_with_threading( https://github.com/elight/acts_as_commentable_with_threading )とacts_as_follower( https://github.com/tcocca/acts_as_follower )という宝石を使用してい ます。

これまでのところ、すべてが正常に機能しています。私のすべてのフォロワーとフォロワーは問題なく機能します。

現在、フォローしているすべてのユーザーのすべてのコメントを取得しようとしています。だから私はこれを試しました

@users = current_user.following_users
@comments = @users.comment_threads.order("updated_at DESC").page(params[:page]).per(10)

ただし、このエラーが返されます。

NoMethodError (undefined method `comment_threads' for #<ActiveRecord::Relation:0x0000000d1b7a58>):

なぜ、どうすればこれを解決できますか?? acts_as_commentable_with_threadingは配列オブジェクトをサポートしていません????

4

1 に答える 1

1

コードに基づいて、おそらく次のようにする必要があります。

user_ids = current_user.following_users.map(&:id)
commentable = User.base_class.name.to_s
@comments = Comment.where(:user_id => user_ids, :commentable_type => commentable).order('created_at DESC')

上記は、1 人のユーザーだけでなく、user_id の配列のコメントを取得します。

于 2013-04-21T18:13:41.383 に答える