This project is archived and is in readonly mode.
setting "arbitrary" default value on route foils named route generation
-
Bill Burcham
- Assigned user set to Pratik
Thank you for looking into this Pratik, however, you misunderstood the issue. Using :defaults doesn't help because the variable whose value I wish to set is not in the path (pattern).
In my example the variable was named :extra_stuff. If I change my route to this as you suggest:
map.home_index '', :controller => 'home', :defaults => {:extra_stuff => 'the_stuff'}And re-run my test:
def test_index_no_explicit_extra_stuff # but URL generation fails if we leave it off assert_generates( '/', :controller => 'home', :action => 'index') endI see this error now:
/builder.rb:117:in `assign_route_options': extra_stuff: No matching segment exists; cannot assign default (ArgumentError)See "no matching segment exists". The whole point is that I wish to set a variable when a match happens. That variable is not part of the original path. The "Agile" book says this is possible (see reference above) and I've found it useful for e.g. setting the layout and for setting other static values that vary based on which routing rule fires.