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?

4

1 に答える 1

7

link_to_next_page ドキュメントによると、env から QUERY_STRING を取得する必要があるため、クエリ パラメータを保持します。

def link_to_next_page(scope, name, options = {})
  params = options.delete(:params) ||(Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {})

期待どおりに動作しない場合は、自分でパラメーターを渡すことができます

<%= link_to_next_page @items, 'Next Page', :params => params %>
于 2013-08-01T00:14:30.280 に答える