Topic: how to add "/" to link_to ???
Hello all,
How can I add "/" at the end of link_to function?
from www.foo.com/bar to www.foo.com/bar using link_to method?
thanks you guys
You are not logged in. Please login or register.
Rails Forum - Ruby on Rails Help and Discussion Forum » Controllers and Views » how to add "/" to link_to ???
Hello all,
How can I add "/" at the end of link_to function?
from www.foo.com/bar to www.foo.com/bar using link_to method?
thanks you guys
Um, the links in your post are no different.
Why do you need the forward slash on the end anyway? It's extraneous.
sorry I meant to say www.foo.com/bar to www.foo.com/bar/
well because without a "/" at the end will do redirect. it will throw 302 (I think) error which users never know about but server will redirect.
Last edited by foozilla (2007-11-12 19:21:23)
This should not happen. These URLs should be 100% equal in their "meaning". Anything else is not HTTP-valid i would say.
Maybe you should rather check the server??? WOuld be interested why it behaves this way ...
anyways, you could only make your own helper:
def slashed_link_to(*args)
link_to(args) + "/"
end
check out the http://developer.yahoo.com/performance/
#redirects
this is why and I got error when I was trying to use lightwindow without the "/" at the end.
thanks
Last edited by foozilla (2007-11-12 19:37:59)
If you're running apache this doesn't affect rails apps because everything runs through mod_rewrite:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
<%= link_to "+ Reply", url_for(:action => 'edit', :id => s ) + "/", :class => 'lightwindow page-options'%>
There is a :trailing_slash option in url_for. See it here.
I'm not sure if you're linking to a controller or just an outside url, but it could be something like this:
<%= link_to "Foo Bar", url_for(:action => 'bar', :trailing_slash => true ) %>
Last edited by chapman (2007-12-03 09:33:44)
:trailing_slash