views:

887

answers:

2

Having this route:

map.foo 'foo/*path', :controller => 'foo', :action => 'index'

I have the following results for the link_to call

link_to "Foo", :controller => 'foo', :path => 'bar/baz'
# <a href="/foo/bar%2Fbaz">Foo</a>

Calling url_for or foo_url directly, even with :escape => false, give me the same url:

foo_url(:path => 'bar/baz', :escape => false, :only_path => true)
# /foo/bar%2Fbaz

I want the resulting url to be: /foo/bar/baz

Is there a way around this without patching rails?

+3  A: 

Instead of passing path a string, give it an array.

link_to "Foo", :controller => 'foo', :path => %w(bar baz)
# <a href="/foo/bar/baz">Foo</a>

If you didn't have the route in your routes file, this same link_to would instead create this:

# <a href="/foo?path[]=bar&path[]=baz">Foo</a>

The only place I could find this documented is in this ticket.

Gordon Wilson
A: 

Any reason why you're needing to generate the URL with that path though?

It would be cleaner to just define an extra route to cover that URL.

madlep
Please use the comment feature for clarifications and such ;-)
webmat