This project is archived and is in readonly mode.
Named routes do not handle parameters with a "/" in the values
-
anupom syam
It seems working fine for me.
app.my_named_route_url('cats/dogs') => "http://www.example.com/help/cats%2Fdogs"
I found appropriate unit tests for this (see test_paths_escaped()) in routing_testrb as well.
Which version are you using?
-
Carl Lerche
- State changed from new to invalid
I tried reproducing this as well and it seems to work for me. I am going to mark this ticket as invalid, but feel free to reopen it if you have more information.
-
theirishpenguin
Thanks for your quick reply folks. I am using version Rails 2.3.2.
I have tried this on a different machine and, like ye, it now works for me. This is very strange as I'd tried this already on a couple of machines. Mustn't be anything to do with Rails though.
Thanks for your quick reply. Much appreciated,
Declan -
theirishpenguin
I have successfully reproduced the bug - It is unfortunate that my original test case was a little vague. Here are the exact steps to reproduce
- Create a new rails app via 'rails farmhouse'
- Inside the app, run './script/generate scaffold pig'
-
Do a './script/console'
./script/generate scaffold pig => Loading development environment (Rails 2.3.2)
app.pigs_url('cat/dog') => "http://www.example.com/pigs.cat%2Fdog"
app.pig_url('catdog') => "http://www.example.com/pigs/catdog"
app.pig_url('cat/dog') ActionController::RoutingError: pig_url failed to generate from {:controller=>"pigs", :id=>"cat/dog", :action=>"show"}, expected: {:controller=>"pigs", :action=>"show"}, diff: {:id=>"cat/dog"}
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:422:inraise_named_route_error' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:386:ingenerate' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:205:inrewrite_path' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:184:inrewrite_url' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:162:inrewrite' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:243:inurl_for' from (eval):16:inpig_url' from (irb):1 -
If I then run rake routes, I get the following route pig GET /pigs/:id(.:format) {:action=>"show", :controller=>"pigs"}
-
So, irrespective of having a forward slash in the value or not, I should get a valid route back for my piggy :-)
I will attempt to reproduce it on another test machine later. If that is successful I will reopen the bug. I don't want to waste your time in the event that it is an environment problem on my end. Just to reiterate I am using Rails 2.3.2. Thanks again.
-
theirishpenguin
Just quick update. I've tested this this against Rails 2.3.3 and I am still getting the same behaviour.
-
PreciousBodilyFluids
Still present on Rails 2.3.5, and rather annoying.
-
Indrek Juhkam
seems to work in rails 3
-
Ken Robertson
I've been experiencing this on Rails3 beta4. I'm working on porting an app from Merb to Rails3, so no experience with whether this is an issue in Rails 2.3.
I also created a bare Rails3 beta4 app and reproduced it with a very simple setup. I created a route like so:
match '/blah/:id' => 'home#blah', :as => :someroute, :constraints => { :id => /[A-Za-z0-9\/]*/ }
Then in my template, simply had:
someroute_path('one/two')
And it throws the error:
ActionController::RoutingError in Home#index No route matches {:controller=>"home", :action=>"blah", :id=>"one/two"}
I dug down about as far as I could go. The issue seems to actually be in rack-mount. On startup of the app, rack-mount composes all the routes and translates the route into named segments. It is during that where the regex for the constraint is being altered to drop the slash.
I've traced it down to Rack::Mount::Utils.parse_regexp, when it calls Regin.parse(regexp). Before that, the regexp is fine, after that, when it converts it into an Expression, it is missing the slash. It seems to use Regin::Parser to parse it and segment it, but haven't had a change to debug it enough to find the cause.
-
Brian Rose
- Tag set to rails 3, router
Does the patch found at https://rails.lighthouseapp.com/projects/8994/tickets/5135-slash-ge... fix this?
-
Ken Robertson
Yes, it does. Somehow I got lead down the wrong path this morning. Must have been lack of sleep.
It was related to the value being escaped. I found I could get around it by using someroute_path(['one','two']). I think splitting the string would be good. I don't know if there are cases when it'd need more than just a slash.
-
Santiago Pastorino
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale