Ruby on rails 我如何获取我的追随者的所有评论?
我用的是一种叫做 使用线程将\u作为\u可注释的\u,并将\u作为\u跟随者 到目前为止,一切正常。我所有的追随者,和追随者的功能没有问题 现在,我正在尝试获取以下所有用户的所有评论。 所以我试过这个Ruby on rails 我如何获取我的追随者的所有评论?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我用的是一种叫做 使用线程将\u作为\u可注释的\u,并将\u作为\u跟随者 到目前为止,一切正常。我所有的追随者,和追随者的功能没有问题 现在,我正在尝试获取以下所有用户的所有评论。 所以我试过这个 @users = current_user.following_users @comments = @users.comment_threads.order("updated_at DESC").page(params[:page]).per(10) 但是,它返回此错误 NoMethodErro
@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不支持数组对象???基于,您可能需要这样做:
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')
上面将获得一组用户ID的注释,不仅仅是一个用户谢谢,但我得到了这个错误:ActiveRecord::StatementInvalid Mysql2::error:字段列表中的列“id”不明确:从用户的内部连接中选择id。followable\u id=users.id和follows.followable\u type='user'其中follows.blocked=0和follows.follower\u id=4和followers.follower\u type='User'和follow.followable_type='User'和users.deleted_at为空:`