There's a bug with url_for(..) mishandling hashes. This becomes especially relevant when using AJAX and trying to pass back some context data without using entire forms.
With this issue the URL:
/mycontroller/myaction/1?my_hash[a]=value_a&my_hash[b]=value_b&etc=1
Would be routed correctly to the controller method:
class my_controller < ApplicationController
def controller_method
// Routing works correctly so you can access
// @params[:my_hash][:b] for example.
render_text url_for(@params)
end
end
But the output of url_for would be incorrect:
/mycontroller/myaction/1?my_hash=avalue_abvalue_b&etc=1
I traced the problem back to url_rewriter.rb in method rewrite_path(..). While it handled array input correctly, it failed to handle hashes.
The attached patch against edge rails fixes the issue by moving the code that
translated from hash to path-elements to another method called in recursion.
This patch also adds a test of this behaviour. Naturally all tests in the actionpack passed successfully with the patch applied.
Would appreciate any comments regarding this patch.
HTH,
Tal Rotbart