Paginate Products List
Learn to paginate our list of products.
We will start slowly by paginating the products list since we don’t have any access restriction. This allows for easier testing.
The kaminari
gem
We need the kaminari
gem for pagination. The kaminari
gem is an easily implementable and customizable paginator. We can add this gem to the Gemfile
by using this command:
$ bundle add kaminari
In this case, we already have kaminari
installed, so we can move forward.
Modify index
function
We will go to the index
action in the app/controllers/api/v1/products_controller.rb
file and add
the pagination methods as ...