O'Reilly logo

Rails, Angular, Postgres, and Bootstrap by David B. Copeland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 we’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.

Handling Pagination in the Controller

For simplicity, we’ll 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required