Rails url_for when passing a nested hash of parameters
I'm looking to do something like the following:
# /app/helpers/application_helper.rb
def custom_filter_url(additional_params={})
new_params = params.clone
new_params[:filter] ||= {}
new_params[:filter] = new_params[:filter].merge(additional_params)
url_for(new_params)
end
In a view (e.g., http://example.com/things?filter%5Bfoo%5D=bar) I would like the following:
<%= link_to "Bar", custom_filter_url(:foo => 'different') %>
To render:
http://e开发者_如何学Cxample.com/things?filter%5Bfoo%5D=different
However, I'm getting this instead:
http://example.com/things?filter[foo]=different
Apparently, the url_for method doesn't fully encode the nested parameters hash/array. How do I get it to do so, or is there a better way of accomplishing this?
精彩评论