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 )的 gem

到目前为止,一切正常。我所有的追随者和追随者都可以正常工作。

现在,我正在尝试获取所有关注用户的所有评论。所以我尝试了这个

@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')

以上将获得一组 user_ids 的评论,而不仅仅是一个用户

于 2013-04-21T18:13:41.383 回答