Paginating the Results Using Bootstrap’s Components

Adding pagination can be done in just two steps: adjusting the query to find the right “page,” and adding pagination controls to the view. There are several RubyGems out there that can help us, but it’s not that much code to just do it ourselves. Since you’ll be porting our view over to Angular in the next chapter, there’s little benefit to integrating a gem at this point.

We’ll take it one step at a time. First, we’ll adjust the controller to handle pagination.

Handle Pagination in the Controller

For simplicity, let’s hard-code the size of a page to ten results, and look for a new parameter, :page, that indicates which page the user wants, with a default of 0.

Get Rails, Angular, Postgres, and Bootstrap, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.