This project is archived and is in readonly mode.
Routing bug when using :constraints
-
Fouad Mardini
- No changes were found…
-
Andrew White
- Milestone cleared.
- State changed from new to open
- Assigned user set to Andrew White
- Tag set to rails 3.0, parameters, routing
- Importance changed from to High
What's happening is that the symbolized path parameters are getting cached in the rack environment hash so when you use them in your redirect you get the params from the first route that matches. As a workaround the routes below do what you want them to do.
RoutingBug::Application.routes.draw do scope "/:country", :country => /all|France|Italy|Spain/ do match "/", :to => "home#index" match "/cities", :to => "home#cities" end match '/:invalid_country', :to => redirect("/all") match '/:invalid_country/cities', :to => redirect("/all/cities") endThe string key path parameters hash is correct so you could use that.
-
Fouad Mardini
Thanks Andrew! Unfortunately, my logic is a bit more involved and the regexp won't do
-
Andrew White
- Assigned user changed from Andrew White to José Valim
Attached patch fixes the issue by caching the symbolized path parameters in the request object rather than the environment hash.
-
Repository
- State changed from open to resolved
(from [ae2c60734a0f71593709608710a0c7507bb8699e]) Cache the symbolized path parameters using a instance variable in the request object rather than the environment hash. This it to prevent stale parameters in later routing constraints/redirects as only the normal path parameters are set by Rack::Mount.
Also if a constraint proc arity is more than one, pass the symbolized path parameters
as the first argument to match redirect proc args and provide easier access.[#5157 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/ae2c60734a0f71593709608710a0c7... -
Repository
(from [df0a7bfb8fa3f0255fe4ab082863f27c43c278d9]) Cache the symbolized path parameters using a instance variable in the request object rather than the environment hash. This it to prevent stale parameters in later routing constraints/redirects as only the normal path parameters are set by Rack::Mount.
Also if a constraint proc arity is more than one, pass the symbolized path parameters
as the first argument to match redirect proc args and provide easier access.[#5157 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/df0a7bfb8fa3f0255fe4ab082863f2...
