21 February 2017

Ruby on Rails | Pagination

As time went by, the number of article in your blog has increased rapidly. Your articles page become very long. To solve this we can use pagination.

Steps:

  1. In your gemfile, add gem 'will_paginate','version' and gem 'bootstrap-will_paginate', 'version' change the version to current version of the gem. 
  2. bundle install --without production --If production group exists-- to install the gem. 
  3. In articles_controller, at index action, change the variable value to Article.paginate(page: params[:page], per_page: 10) If you want to show more than 10 articles, simply change the number. 
  4. Add <%= will_paginate %> wherever you want to place the pagination.

No comments:

Post a Comment