How to use pagination in rails 3.2.3?

守給你的承諾、 提交于 2019-12-08 05:48:56

问题


I'm new in RoR, and I want to include pagination in my application.

Which is the best way to perform this task? Please suggest me. Is it possible to use will_paginate gem in rails 3.2.3 ?

If yes, in which method I should include:

Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')  

Post.page(params[:page]).order('created_at DESC')    

回答1:


Yes, it is possible to use will_paginate gem in rails 3.2.3 applications.

And the code will depends on what each action will perform.

The code below usually goes on a #index method, in your PostsController.

@posts = Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')

So, in your posts/index.html.erb view file you can use the following code to display the pagination links:

<%= will_paginate @posts %>


来源:https://stackoverflow.com/questions/10867977/how-to-use-pagination-in-rails-3-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!