lib/ransack/helpers/form_helper.rb in ransack-0.6.0 vs lib/ransack/helpers/form_helper.rb in ransack-0.7.0
- old
+ new
@@ -23,13 +23,19 @@
form_for(record, options, &proc)
end
def sort_link(search, attribute, *args)
+ # Extract out a routing proxy for url_for scoping later
+ if search.is_a?(Array)
+ routing_proxy = search.shift
+ search = search.first
+ end
+
raise TypeError, "First argument must be a Ransack::Search!" unless Search === search
- search_params = params[:q] || {}.with_indifferent_access
+ search_params = params[search.context.search_key] || {}.with_indifferent_access
attr_name = attribute.to_s
name = (args.size > 0 && !args.first.is_a?(Hash)) ? args.shift.to_s : Translate.attribute(attr_name, :context => search.context)
@@ -48,16 +54,23 @@
end
html_options = args.first.is_a?(Hash) ? args.shift.dup : {}
css = ['sort_link', current_dir].compact.join(' ')
html_options[:class] = [css, html_options[:class]].compact.join(' ')
- options.merge!(
- :q => search_params.merge(:s => "#{attr_name} #{new_dir}")
- )
+ query_hash = {}
+ query_hash[search.context.search_key] = search_params.merge(:s => "#{attr_name} #{new_dir}")
+ options.merge!(query_hash)
+
+ url = if routing_proxy && respond_to?(routing_proxy)
+ send(routing_proxy).url_for(options)
+ else
+ url_for(options)
+ end
+
link_to [ERB::Util.h(name), order_indicator_for(current_dir)].compact.join(' ').html_safe,
- url_for(options),
- html_options
+ url,
+ html_options
end
private
def order_indicator_for(order)
@@ -70,6 +83,6 @@
end
end
end
end
-end
\ No newline at end of file
+end