[Ruby] Pagination implementation with gem’kaminari’

less than 1 minute read

Preparation

  • Added’kaminari’to Gemfile
gem 'kaminari'
  • bundle install

Implementation example

  • Get 50 records from the Item model in one search
Item.all.page(1).per(50)
  • When implementing for an array
Display 10 records per page
Kaminari.paginate_array(array).page(params[1]).per(10)