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