Thursday, March 15, 2012

How can pagination be done in ruby on rails 3.1?

The more recent kaminari gem can be used in Rails 3. You can refer https://github.com/amatsuda/kaminari
it is very simple to use.
Put this line in your Gemfile:
gem 'kaminari'
Then do bundle install
Typically, your controller code will look like this:
@users = User.order(:name).page params[:page]
On the views Just call the paginate helper:
<%= paginate @users %>
Now you can see the paginated result..

No comments:

Post a Comment