Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

How to use pagination in rails 3.2.3?

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')    

Upvotes: 1

Views: 5422

Answers (1)

Kleber S.
Kleber S.

Reputation: 8260

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 %>

Upvotes: 3

Related Questions