我希望做以下事情:
# /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
在视图中(例如http://example.com/things?filter%5Bfoo%5D=bar),我想要以下内容:
<%= link_to "Bar", custom_filter_url(:foo => 'different') %>
渲染:
http://example.com/things?filter%5Bfoo%5D=different
然而,我得到了这个:
http://example.com/things?filter[foo]=different
显然,url_for方法没有完全编码嵌套参数hash / array。我如何做到这一点,还是有更好的方法来实现这一目标?