Permalink
Browse files

Exclude basic form params from pagination links

Even though the basic form params will be blacklisted, other params
submitted from a form still gets appended to the links. However, there
is no good way to detect what should be excluded and what shouldn't. If
a particular parameter(e.g. params[:user]) should be excluded, the
example below could be a workaround:

    paginate @users, params: {user: nil}

fixes #131. fixes #182
  • Loading branch information...
yuki24 committed Mar 13, 2014
1 parent 67b4284 commit 2fd7d36b72af73d2506f8e2ab68704d804f70fc5
Showing with 18 additions and 1 deletion.
  1. +3 −1 lib/kaminari/helpers/tags.rb
  2. +15 −0 spec/helpers/helpers_spec.rb
@@ -1,5 +1,7 @@
module Kaminari
module Helpers
PARAM_KEY_BLACKLIST = :authenticity_token, :commit, :utf8, :_method
# A tag stands for an HTML tag inside the paginator.
# Basically, a tag has its own partial template file, so every tag can be
# rendered into String using its partial template.
@@ -17,7 +19,7 @@ def initialize(template, options = {}) #:nodoc:
@template, @options = template, options.dup
@param_name = @options.delete(:param_name) || Kaminari.config.param_name
@theme = @options[:theme] ? "#{@options.delete(:theme)}/" : ''
@params = @options[:params] ? template.params.merge(@options.delete :params) : template.params
@params = template.params.except(*PARAM_KEY_BLACKLIST).merge(@options.delete(:params) || {})
end
def to_s(locals = {}) #:nodoc:
@@ -18,6 +18,21 @@
end
subject { @paginator.page_tag(template).instance_variable_get('@params') }
it { should == {:controller => 'foo', :action => 'bar'} }
context "when params has form params" do
before do
stub(template).params do
{
:authenticity_token => "token",
:commit => "submit",
:utf8 => "",
:_method => "patch"
}
end
end
it { should == {:controller => 'foo', :action => 'bar'} }
end
end
describe '#param_name' do

0 comments on commit 2fd7d36

Please sign in to comment.