Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11460 (new defect)

Opened 4 months ago

Last modified 4 months ago

[PATCH] Named route helper hash_for_*_path and hash_for_*_url does not accept ordered parameters as does the regular *_url helper

Reported by: berpasan Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: bug has_patch tested
Cc:

Description

If you have a named route such as

map.multi '/people/go/:foo/:bar/joe/:id', :controller => 'people', :action => 'multi'

You can use

multi_path('foo_value', 'bar_value', 'id_value')

instead of

multi_path(:foo=>'foo_value', :bar=>'bar_value', :id=>'id_value')

But if you do:

hash_for_multi_path('foo_value', 'bar_value', 'id_value')

The sky will fall on your head in the form of an exception:

TypeError: can't convert Fixnum into Hash

Tested against [9119].

The attached patch will add the tests to actionpack.

The method that needs to be fixed is in the file route_set.rb, line: 139 (define_hash_access).

Attachments

hash_for_method_with_ordered_parameters_test.diff (1.3 kB) - added by berpasan on 03/28/08 20:42:33.
Tests hash_for helpers with ordered parameters
hash_for_method_with_ordered_parameters_bug_patch.diff (4.0 kB) - added by berpasan on 03/28/08 23:34:38.
Patch that fixes the bug (includes the test from the previous patch)

Change History

03/28/08 20:42:33 changed by berpasan

  • attachment hash_for_method_with_ordered_parameters_test.diff added.

Tests hash_for helpers with ordered parameters

03/28/08 23:34:38 changed by berpasan

  • attachment hash_for_method_with_ordered_parameters_bug_patch.diff added.

Patch that fixes the bug (includes the test from the previous patch)

03/28/08 23:42:37 changed by berpasan

  • keywords changed from bug to bug has_patch tested.
  • summary changed from Named route helper hash_for_*_path and hash_for_*_url does not accept ordered parameters as does the regular *_url helper to [PATCH] Named route helper hash_for_*_path and hash_for_*_url does not accept ordered parameters as does the regular *_url helper.

I managed to fix it by moving some logic from the method define_url_helper (which creates a named route helper such as thing_url ) to define_hash_access in route_set.rb.

The patch file looks a bit confusing because of this move, but it was actually a small change.

All actionpack tests are working (as of [9119]).

Please give your "+1"s for it, so it gets applied. Thanks!!