Skip to content

Commit

Permalink
Rails 5 fix for keeping query parameters in pagination links
Browse files Browse the repository at this point in the history
In Rails 5, `params` hash is no longer a simple
HashWithIndifferentAccess, but an ActionController::Parameters instance
with implements the "strong parameters" concept that prevents mass
assignment.

Fixes #501, closes #502, fixes #486, closes #483
  • Loading branch information
mislav committed Sep 21, 2016
1 parent addcd10 commit 89c8b6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/will_paginate/view_helpers/link_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ def rel_value(page)
end

def symbolized_update(target, other, blacklist = nil)
other.each do |key, value|
other.each_pair do |key, value|
key = key.to_sym
existing = target[key]
next if blacklist && blacklist.include?(key)

if value.is_a?(Hash) and (existing.is_a?(Hash) or existing.nil?)
if value.respond_to?(:each_pair) and (existing.is_a?(Hash) or existing.nil?)
symbolized_update(existing || (target[key] = {}), value)
else
target[key] = value
Expand Down
12 changes: 10 additions & 2 deletions spec/view_helpers/action_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class DummyRequest
def initialize(controller)
@controller = controller
@get = true
@params = {}
@params = {}.with_indifferent_access
@symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
end

Expand All @@ -442,7 +442,11 @@ def script_name

def params(more = nil)
@params.update(more) if more
@params
if defined?(ActionController::Parameters)
ActionController::Parameters.new(@params)
else
@params
end
end

def host_with_port
Expand All @@ -458,3 +462,7 @@ def protocol
'http:'
end
end

if defined?(ActionController::Parameters)
ActionController::Parameters.permit_all_parameters = false
end

0 comments on commit 89c8b6c

Please sign in to comment.