2013-04-21 66 views
0

我使用所谓的 acts_as_commentable_with_threadinghttps://github.com/elight/acts_as_commentable_with_threading)宝石和acts_as_followerhttps://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不支持数组对象?

回答

1

基础上code,你可能会需要这样的东西,如:

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数组,而不仅仅是一个用户

+0

感谢,但我已经得到了这个错误:('ActiveRecord :: StatementInvalid(Mysql2 ::错误:列'ID'在字段列表中是不明确的:SELECT ID FROM'用户'INNER JOIN'后面'ON'跟随''.'followable_id' ='用户'.'''后跟''.''''''''''''''''''''''''''''''''''和''后面跟随''''和'跟随'。 'follow'.'''''''lowlow_type' ='User'AND('use rs'.'deleted_at'是NULL)): ' – cat 2013-04-21 18:33:48

+0

@cat - 更新到不会给你那个错误 – 2013-04-21 21:28:32

+0

非常感谢:)它的工作 – cat 2013-04-22 11:32:06

相关问题