This project is archived and is in readonly mode.
[PATCH] Defaults support for the new Router DSL
-
Andrew White
- Assigned user set to josh
Yep, I can confirm this. It also means you can't do routes with optional params, e.g:
# Old style map.page 'pages/:id', :controller => 'pages', :action => 'show', :id => 'default' # GET /pages -> { :controller => 'pages', :action => 'show', :id => 'default' } # New style match 'pages/:id' => 'pages#show', :id => 'default' # GET /pages -> Routing ErrorI thought it may be intentional but even if you tried to add a match for 'pages' you'd have to route it to a different action that set a default :id. I can come up with a patch but some feedback would be nice on whether only defaults in an explicit sub hash (e.g :defaults => { }) or any extra keys in the options hash as well. Regexp requirements can still be set in the options hash so I'm guessing that defaults should be the same.
-
Andrew White
Oops - optional params are now specified using parentheses, so I take that back about not being able to specify them.
-
Andrew White
Okay the attached patch adds defaults support to the new routing DSL allowing the following:
root :to => 'pages#show', :id => 'home' %w(about contact services).each do |page| match page => 'pages#show', :as => "#{page}_page", :id => page endIt supports specifying defaults in the options hash, in a defaults hash as part of the options hash and also as a scope.
-
Rizwan Reza
- Milestone cleared.
- Tag set to 3.0, bug, router
- State changed from new to verified
- Title changed from Unable to specify default values for params hash to [PATCH] Defaults support for the new Router DSL
+1
Patch applies cleanly and all tests pass. Fixes the issue. Nice work, Andrew.
-
Repository
- State changed from verified to resolved
(from [3d746fcdb584767c476408f395320e934fd5383e]) Add parameter defaults support to new routing DSL [#4265 [PATCH] Defaults support for the new Router DSL state:resolved]
Signed-off-by: wycats wycats@gmail.com
http://github.com/rails/rails/commit/3d746fcdb584767c476408f395320e...
