Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我如何获取我的追随者的所有评论?_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 我如何获取我的追随者的所有评论?

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

我用的是一种叫做 使用线程将\u作为\u可注释的\u,并将\u作为\u跟随者

到目前为止,一切正常。我所有的追随者,和追随者的功能没有问题

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

@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为空:`