Skip to content

Commit

Permalink
Merge pull request activerecord-hackery#634 from seanlinsley/rails-5-…
Browse files Browse the repository at this point in the history
…params-refactor

Rails 5 params: instance_variable_get -> to_unsafe_h
  • Loading branch information
jonatack committed Jan 5, 2016
2 parents ceb136f + 989d69f commit e320178
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
9 changes: 2 additions & 7 deletions lib/ransack/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def url(routing_proxy, options_for_url)
class SortLink
def initialize(search, attribute, args, params)
@search = search
@params = parameters_hash(params)
@params = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
@field = attribute.to_s
@sort_fields = extract_sort_fields_and_mutate_args!(args).compact
@current_dir = existing_sort_direction
Expand Down Expand Up @@ -120,11 +120,6 @@ def html_options(args)

private

def parameters_hash(params)
return params unless params.instance_variable_defined?(:@parameters)
params.instance_variable_get(:@parameters)
end

def extract_sort_fields_and_mutate_args!(args)
return args.shift if args[0].is_a?(Array)
[@field]
Expand All @@ -145,7 +140,7 @@ def search_and_sort_params
end

def search_params
parameters_hash(@params[@search.context.search_key]).presence || {}
@params[@search.context.search_key].presence || {}
end

def sort_params
Expand Down
4 changes: 1 addition & 3 deletions lib/ransack/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ class Search
:translate, :to => :base

def initialize(object, params = {}, options = {})
if params.instance_variable_defined?(:@parameters)
params = params.instance_variable_get :@parameters
end
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
if params.is_a? Hash
params = params.dup
params.delete_if { |k, v| [*v].all?{ |i| i.blank? && i != false } }
Expand Down

0 comments on commit e320178

Please sign in to comment.