Tutorials

Customize Kaminari Pagination

Kaminari is a popular pagination gem for Rails application and provides a decent default template to get started.

In this tutorial, we will customize Kaminari template and allow to change dynamically the limit per page. We will use the following mock-up:

To get started, follow the steps below:

So we start by editing the app/views/kaminari/_paginator.html.erb partial:

Next, to display Bootstrap glyphicons for navigation we edit the locale file config/locales/en.yml

 

Now it’s time to add dynamic page limits, I suggest to add the page sizes inside Kaminari config file like to avoid hardcoding values in the view.

config/initializers/kaminari_config.rb file

 

And to display the pagination alongside filter links

app/views/articles/index.html.erb

Next step is to edit the articles_controller file

and to wrap it up we add a simple CSS:

The code implementation is available on the following Github repo.

Have fun and keep coding 🙂