Index: actionpack/test/controller/url_rewriter_test.rb =================================================================== --- actionpack/test/controller/url_rewriter_test.rb (revision 3524) +++ actionpack/test/controller/url_rewriter_test.rb (working copy) @@ -19,7 +19,9 @@ def test_expand_array_build_query_string assert_query_equal '?x[]=1&x[]=2', @rewriter.send(:build_query_string, :x => [1, 2]) end - + def test_multidimensional_hashes_build_query_string + assert_query_equal '?this%5Bis%5D%5Ba%5D=test&this%5Bis_also%5D%5Ba%5D=hash', @rewriter.send(:build_query_string, :this => { 'is' => {'a' => 'test'}, 'is_also' => {'a' => 'hash'} }) + end def test_escape_spaces_build_query_string_selected_keys assert_query_equal '?x=hello+world', @rewriter.send(:build_query_string, {:x => 'hello world', :y => 'goodbye world'}, [:x]) end Index: actionpack/lib/action_controller/url_rewriter.rb =================================================================== --- actionpack/lib/action_controller/url_rewriter.rb (revision 3524) +++ actionpack/lib/action_controller/url_rewriter.rb (working copy) @@ -55,6 +55,8 @@ query_string = "" only_keys ||= hash.keys + + flatten_query_hash!(hash, only_keys) only_keys.each do |key| value = hash[key] @@ -70,5 +72,20 @@ query_string << ("?" + elements.join("&")) unless elements.empty? query_string end + + # Flattens the query hash so multidimensional hashes in the params hash work properly. + def flatten_query_hash!(hash, only_keys) + hash.each do |k,v| + next unless v.kind_of? Hash + v.each do |n,o| + hash["#{k}[#{n}]"] = o + only_keys << "#{k}[#{n}]" + end + hash.delete(k) + only_keys.delete(k) + flatten_query_hash!(hash, only_keys) + end + end + end end