Kaminari 分页错误
我想用 Kaminari 分页 gem 对我的对象进行分页。我的控制器中有这一行:
@products = Product.order("id").find_all_by_id(params[:id])
我的视图中的那一行:
<%= paginate @products %>
我的模型中的那一行:
paginates_per 20
当我打开应该列出我的对象的页面时,我收到此错误消息:
undefined method `current_page' for #<Array:0x2964690>
在我的 处引发了异常<%= 分页@products %>
行。
我已经为另一个项目做了分页,效果非常好。有人可以帮我吗?
谢谢 !
I would like to paginate my objects with the Kaminari pagination gem. I have this line in my controller:
@products = Product.order("id").find_all_by_id(params[:id])
That line in my view:
<%= paginate @products %>
And that line in my model:
paginates_per 20
When I open my page where my objects are supposed to be listed, I have this error message :
undefined method `current_page' for #<Array:0x2964690>
The exception is raised at my <%= paginate @products %>
line.
I have already made a pagination for another project and it was working really great. Could someone help me please ?
Thank you !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
问题是
find_all_by_*
返回一个数组,而不是 ActiveRecord::Relation。你可以做这样的事情,
另外,你可能应该有一个
.page(params[:page])
。Edit:
The problem is that
find_all_by_*
returns an array, not an ActiveRecord::Relation.You can do something like this instead
Also, you should probably have a
.page(params[:page])
in there.