Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Kaminari to always include page param?

Kaminari's URL generation omits the page param if it is generating the link back to the first page. However, the application is designed to select a random page if the page parameter is omitted. Kaminari's default behaviour, then, precludes paginating back to the first page in a reliable way.

I've resolved this issue, and will post my solution below a bit later, but I wanted to post this question for posterity, and I'm also pretty new to Rails, thus I'm not sure my solution is the best or most elegant, and I'm interested in improvements and refinements, if just for my own selfish edification!

like image 725
Daniel Wright Avatar asked Mar 30 '11 14:03

Daniel Wright


2 Answers

This is the answer for 2018 as am writing this :

Like it's stated in the kaminari github home page

Run this to create a config file for kaminari :

rails g kaminari:config

This will create a file kaminari_config.rb in your config/initializers folder

Uncomment the line : config.params_on_first_page = false and replace false by true :

config.params_on_first_page = true

Restart your server if necessary. That's it :)

like image 147
medBouzid Avatar answered Sep 29 '22 18:09

medBouzid


As of today (July 2016), the Kaminari master branch includes a config option params_on_first_page, which is false by default.

Setting this config option to true will include page params for all pages, including page 1.

Note that the master branch isn't a stable release, so use with caution!

like image 32
deepmotion Avatar answered Sep 29 '22 17:09

deepmotion