To divide a large number of records into multiple parts, we use pagination. It allows users to display a part of records only. Loading all records on a single page may take time, so it is always recommended to created pagination. In will_paginate-bootstrap gem integrates the Bootstrap pagination component. The usage for this is extremely simple and it magically works. So let’s take a look at adding this.
STEP 1. gem install will_paginate-bootstrap
STEP 2. Open app/controller/posts_controller.rb and it adds necessary parameters in the resultant collection of records to display pagination links in the front-end (.erb).
STEP 3. Open app/views/posts/index.html.erb for adding pagination links and also add bootstrap CDN links.
It will add pagination links like, <- Older 1 2 Newer-> on front-end.
STEP 4. A collection of extensions for the database layer that enable paginated queries, and view helpers for popular frameworks that render pagination links. With the proper combination of view helpers and CSS styling.
The number of Pages here 1, 2 is decided based on the total numbers of records that you have in your database, the final result can look like this:
PAGE NO 1. (Paginated result data)
PAGE NO 2. (Paginated result data)