Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change number of elements per page with <%= will_paginate %>

I'm using the 'will_paginate' gem. The default is 30 elements per page. How do I customize this?

like image 956
Justin Meltzer Avatar asked Mar 23 '11 00:03

Justin Meltzer


2 Answers

If your controller is called User, you can do something like this in your controller: @users = User.paginate :page => params[:page], :per_page => 10, :order => 'name ASC' This will show 10 results per page.

In your view: <%= will_paginate @users %>

like image 196
Raunak Avatar answered Oct 05 '22 22:10

Raunak


See the per_page option here:

https://github.com/mislav/will_paginate/wiki

It will allow you to change the number displayed per page, for anytime that model is paginated.

For a controller/action specific approach see Raunak's answer.

like image 20
ctcherry Avatar answered Oct 05 '22 22:10

ctcherry