【发布时间】:2020-01-13 21:36:55
【问题描述】:
我在控制器中的 will_paginate 代码:
@posts = Post.paginate(page: params[:page], per_page: 100).order('created_at DESC')
替换它的我的页面代码:
@pagy, @posts = pagy_countless(Post.order('created_at DESC'), items:5, link_extra: 'class="" style="color:#222222; margin:3px;"')
我认为问题出在哪里:
<% @posts.where(user_id: current_user.friends).each do |post| %>
错误信息:
undefined method `where' for #<Array:0x00007f94329d1f70>
Did you mean? when
我做错了什么?之前的 will_paginate 实现在显示用户朋友的所有帖子方面起作用。我不知道切换到 pagey 发生了什么变化。
更新:
所以目前,我通过将“where...”逻辑移动到控制器来解决这个问题。所以:
@pagy, @posts = pagy_countless(Post.where(user_id: current_user.friends).order('created_at DESC'), items:5, link_extra: 'class="" style="color:#222222; margin:3px;"')
现在它像以前一样工作了。但我仍然对为什么必须这样做感到困惑。
【问题讨论】:
标签: ruby-on-rails ruby pagination will-paginate