This project is archived and is in readonly mode.

#1967 ✓invalid
Walter Smith

Named routes with nil params have extra slashes

Reported by Walter Smith | February 14th, 2009 @ 04:49 AM | in 2.x

Define a named route like this:

map.foo '/foo/:id', :controller => 'test', :action => 'foo', :id => nil

In 2.2.2 the following was true:

foo_url ==> "http://host/foo"
url_for(:controller => 'test', :action => 'foo') ==> "http://host/foo"

Now in 2.3RC1 the behavior has changed:

foo_url ==> "http://host/foo/"
url_for(:controller => 'test', :action => 'foo') ==> "http://host/foo"

The trailing slash seems wrong, and in any case the results of foo_url and url_for should be the same, right?

Comments and changes to this ticket

  • josh

    josh February 16th, 2009 @ 08:21 PM

    • State changed from “new” to “invalid”

    There should not be a trailing slash by default. I think there is some sort of routing option to configure this though, you may want to check that.

    I created a fresh Rails app and it seems to be correct.

    
    posts_path: /posts
    posts_url: http://localhost:3000/posts
    url_for(:controller => "posts"): /posts
    
  • josh
  • Walter Smith

    Walter Smith February 16th, 2009 @ 10:03 PM

    I did my test with a fresh app too. You don't show the route you used -- it matters whether you have the nil default value in the route. (:id => nil)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Tags