3

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?

AlexQueue
  • 6,353
  • 5
  • 35
  • 44

1 Answers1

7

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 %>
allenwei
  • 4,047
  • 5
  • 23
  • 26
  • Works! It's asking for the next page from http://example.com/products?page=2&filter=examplefilter rather than http://example.com/products/examplefilter?page=2 though, which is not ideal. – AlexQueue Aug 01 '13 at 17:01