Filtered Pagination with Kaminari
activerecord, kaminari, pagination, ruby-on-rails
Solution
according link_to_next_page document, it should get QUERY_STRING from env, so it will keep query parameter
def link_to_next_page(scope, name, options = {})
params = options.delete(:params) ||(Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})
if it not work as expect, you can pass params yourself
<%= link_to_next_page @items, 'Next Page', :params => params %>
Problem
I set up a website that uses AJAX-pagination powered by Kaminari. I also have set up simple filtering and searching, so you can browse my list on http://example.com/products/filter?query=blah. I'm using Kaminari's built-in `link_to_next_page` helper to generate my next-page link. The problem comes about because this generated link ignores my queries/filters, sending anyone on http://example.com/products/filter?query=blah to http://example.com/products?page=2 One solution I've toyed with is to rewrite the link_to_next_page helper to include my filters and search-terms, but this is (as with all things) more work than expected. Is there a better way?