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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With