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:
- In your gemfile, add
gem 'will_paginate','version' and gem 'bootstrap-will_paginate', 'version' change the version to current version of the gem. bundle install --without production --If production group exists-- to install the gem. - 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. - Add
<%= will_paginate %> wherever you want to place the pagination.
No comments:
Post a Comment