I am using Kaminari gem with rails 3.2 application. Its working properly. Now i want to add a custom per page drop down with [5, 10, 15, 20] options. With per page selected pagination links should preserve the per page value. What is the best approach to implement this custom per page functionality?
Add a GET form.
<%= form_tag posts_path, method: :get do %>
<%= select_tag :limit, options_for_select([5, 10, 15, 20], selected: params[:limit] || 10) %>
<% end %>
And in your controller add
@posts = @posts.per(params[:limit]) if params[:limit]
This is assuming your resource is posts, but obviously you can change it to whatever it is you are paginating.
Of course you need to trigger the form somehow, either by adding a submit button or through javascript.
There is best guide which simply explains how kaminari gem works, i suggest you just read over that tutorial.http://railscasts.com/episodes/254-pagination-with-kaminari. The kaminari gem is the best one which helps to paginate option.
@products = Product.order("name").page(params[:page]).per(5)
for your custom option you have to read your option from a drop down box and replace the 5 with variable that we have get from user. for the drop down box
<td><%= f.select :experiance_year, options_for_select([*0..10 ],0)%></td>
here experiance_year is the variable that get input from user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With