Ruby on Rails:will_paginate 无法正常工作
如果我单击下一个或上一个链接,它不会转到下一页或上一页。
所有帖子都在同一页面上,但底部有下一个、上一个的链接。
在PostsController中:
@posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC')
在posts/index中:
<%= will_paginate @posts%>
will_paginate的问题出在哪里?
If I click the next or previous link it doesn't go to the next or previous page.
All posts are on same page, but there are links next, previous at bottom.
In PostsController:
@posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC')
in posts/index:
<%= will_paginate @posts%>
Where is the problem with will_paginate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
分页前必须先订购,
所以,将其更改为
You have to order before paginate,
so, change it to
不确定这是否导致您的错误,但排序应该在 will_paginate 之外完成。
这就是在 Rails 3 中应该如何完成的。
我在控制器中设置 per_page 参数时也遇到了麻烦。您可以尝试在模型中设置它。
Not sure if this is causing your error, but ordering should be done outside of will_paginate.
This is how it should be done in Rails 3.
I've also had trouble setting the per_page parameter within the controller. You could try setting it in the model instead.
更新到
will_paginate , '3.1.7'
解决了我的问题Updating to
will_paginate , '3.1.7'
solved my issues