Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Named routes do not handle parameters with a "/" in the values

#2905

Steps to reproduce

  • Create an application which has at least one named route named route

  • Start up ./script/console and type

app.my_named_route_url('cats/dogs')

... replacing my_named_route with the route name of your choice

Expected result

  • A route is successfully generated

Actual result

  • The following error

ActionController::RoutingError: user_url failed to generate from {:action=>"show", :controller=>"users", :id=>"cats/dogs"}, expected: {:controller=>"users", :action=>"show"}, diff: {:id=>"cats/dogs"}

from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:422:in `raise_named_route_error'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:386:in `generate'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:205:in `rewrite_path'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:184:in `rewrite_url'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/url_rewriter.rb:162:in `rewrite'
from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:243:in `url_for'
from (eval):16:in `user_url'
from (irb):7

Reported by theirishpenguin · July 13th, 2009 @ 03:17 PM

State: stale
Milestone: 3.x
Assigned to: Carl Lerche Carl Lerche
Importance: Low

Activity

  1. anupom syam
    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?

    July 14th, 2009 @ 07:36 PM

  2. Carl Lerche
    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.

    July 15th, 2009 @ 09:42 PM

  3. theirishpenguin
    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

    July 16th, 2009 @ 10:49 PM

  4. theirishpenguin
    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:in raise_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:in rewrite_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:in rewrite' from /var/lib/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:243:inurl_for' from (eval):16:in pig_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.

    July 17th, 2009 @ 11:26 AM

  5. theirishpenguin
    theirishpenguin

    Just quick update. I've tested this this against Rails 2.3.3 and I am still getting the same behaviour.

    July 24th, 2009 @ 02:28 PM

  6. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Carl Lerche
    • State changed from invalid to open

    reopening

    August 3rd, 2009 @ 06:16 AM

  7. PreciousBodilyFluids
    PreciousBodilyFluids

    Still present on Rails 2.3.5, and rather annoying.

    December 22nd, 2009 @ 02:14 AM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  9. Indrek Juhkam
    Indrek Juhkam

    seems to work in rails 3

    June 5th, 2010 @ 09:08 PM

  10. Ken Robertson
    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.

    July 21st, 2010 @ 06:25 PM

  11. Brian Rose
  12. Ken Robertson
    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.

    July 21st, 2010 @ 10:52 PM

  13. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:52 AM

  14. Santiago Pastorino
    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.

    February 9th, 2011 @ 12:31 AM

  15. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 9th, 2011 @ 12:31 AM

  16. bingbing