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.

Routing with a blank path_prefix causes a bad url to generate

#2122

edit Long complex description has been moved to my blog: http://www.somethingunimportant.... I have now updated this ticket to walk you through a simple example to reproduce this bug.

> rails bug

> cd bug

Edit routes.rb to include:


  map.connect "/applicants/:id", :controller => "applicants", :action => "show", :path_prefix => ""

> rake routes

(in /Users/abloom/Sites/bug)

//applicants/:id {:controller=>"applicants", :action=>"show"}

Edit routes.rb to include:


  map.connect "/applicants/:id", :controller => "applicants", :action => "show", :path_prefix => nil

> rake routes

(in /Users/abloom/Sites/bug)

/applicants/:id {:controller=>"applicants", :action=>"show"}

Notice how with the path_prefix set to an empty string the route builder generates an extra slash, but with it set to nil the path looks normal.

Reported by Andrew Bloom · March 3rd, 2009 @ 10:22 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Andrew Bloom
    Andrew Bloom
    • Tag changed from 2.x, routing to 2.2, 2.3, edge, patch, routing

    previous patch was against tags/2.3.0, this new one is against edge and has more tests.

    March 4th, 2009 @ 03:48 AM

  2. Andrew Bloom
  3. Michael Koziarski
    Michael Koziarski

    I'm not sure I follow why you're passing an empty string there though? Seems wrong to just silently ignore a value that was passed?

    March 5th, 2009 @ 08:21 PM

  4. Andrew Bloom
    Andrew Bloom

    The blank string came when trying to build routes like this:

    path_prefix = (%w(development test).include?(RAILS_ENV) ? "admin" : "") map.namespace(:admin, :path_prefix => path_prefix) do |admin|

    ...
    
    

    end

    Yes, it could easily by fixed by making the conditional return nil instead of "", but it still seems like adding the / when there is no slug isn't appropriate.

    March 5th, 2009 @ 08:23 PM

  5. Andrew Bloom
    Andrew Bloom
    
    path_prefix = (%w(development test).include?(RAILS_ENV) ? "admin" : "") 
    map.namespace(:admin, :path_prefix => path_prefix) do |admin|
        ...
    end
    

    (can we get a preview function on comments before posting them?)

    March 5th, 2009 @ 08:24 PM

  6. CancelProfileIsBroken
    CancelProfileIsBroken

    I'm +1 on this. We've had two different people hit this, the fixed behavior seems reasonably intuitive and I can't think of anything else we'd want to do with an empty :path_prefix.

    March 7th, 2009 @ 03:58 PM

  7. Repository
    Repository
    • State changed from new to resolved

    (from [90dba00822acd1e01f7a39625668ee74ffe5f061]) Ensure blank path_prefix works as expected [#2122 Routing with a blank path_prefix causes a bad url to generate state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 9th, 2009 @ 03:30 PM