January 2016
Intermediate to advanced
240 pages
7h 36m
English
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.
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.
Read now
Unlock full access