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.

url_for doesn't accept dot characters

#4443

When I have a route like

get '/:page' => "pages#show", :constraints => {:page => /.+/}, :as => :page

Rails raises an error if I try to use a route like

<%= link_to "Sample", page_path("sample.pdf") %>

The error:

ActionController::RoutingError in Pages#index
No route matches {:controller=>"pages", :constraints=>{:page=>/.+/}, :page=>"sample.pdf", :action=>"show"}

On line #2 of app/views/pages/index.html.erb

    1: <p>
    2:  <%= link_to "Sample", page_path("sample.pdf") %>
    3: </p>

    app/views/pages/index.html.erb:2:in `_render_template__553364074_2179637920_0'

I made it work by replacing dots for its escaped equivalent:

<%= link_to "Sample", page_path("sample.pdf".gsub(/\./, "%2E")) %>

Here's my setup:

ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.0.0]
Rails 3.0.0.beta3

Reported by Nando Vieira · April 20th, 2010 @ 02:26 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Nando Vieira
    Nando Vieira
    • Tag changed from rails3 url_for bug to bug, rails3, url_for

    April 20th, 2010 @ 02:26 PM

  2. Nando Vieira
    Nando Vieira
    • Tag changed from bug, rails3, url_for to 3.0.0.beta3, bug, rails3, url_for

    April 20th, 2010 @ 02:28 PM

  3. Ryan Bigg
    Ryan Bigg

    Shouldn't that be :constraints not :contraints?

    April 21st, 2010 @ 01:42 AM

  4. Nando Vieira
    Nando Vieira

    You're right. That's a typo. Just updated the code.

    April 21st, 2010 @ 03:22 AM

  5. Ryan Bigg
    Ryan Bigg

    You may want to update the error too.

    April 21st, 2010 @ 03:25 AM

  6. Tim Rosenblatt
    Tim Rosenblatt

    Could not reproduce when testing with

    get '/:page' => "pages#show", :constraints => {:page => /.+/}, :as => :page
    

    and

    <%= link_to "Sample", page_path("sample.pdf") %>
    

    under

    ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]
    Rails 3.0.0.beta3

    April 21st, 2010 @ 04:50 AM

  7. kates
    kates

    Could not reproduce it either using
    ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]
    Rails 3.0.0.beta3

    April 21st, 2010 @ 10:49 AM

  8. Paul Barry
    Paul Barry

    Not able to reproduce in master aaaa1782b44c620cecb97238534a2bd2be5d365a with ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin10.3.0], MBARI 0x6770, Ruby Enterprise Edition 2010.01

    April 24th, 2010 @ 08:29 PM

  9. Andrew White
    Andrew White
    • State changed from new to resolved
    • Importance changed from to Low

    Appears to resolved in master - please post here if you can reproduce.

    June 28th, 2010 @ 01:51 PM