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

Re: how to add "/" to link_to ???

Um, the links in your post are no different.

Why do you need the forward slash on the end anyway? It's extraneous.

Re: how to add "/" to link_to ???

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)

Re: how to add "/" to link_to ???

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

Re: how to add "/" to link_to ???

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)

Re: how to add "/" to link_to ???

If you're running apache this doesn't affect rails apps because everything runs through mod_rewrite:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Re: how to add "/" to link_to ???

<%= link_to "+ Reply", url_for(:action => 'edit', :id => s ) + "/", :class => 'lightwindow page-options'%>

Re: how to add "/" to link_to ???

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)

Re: how to add "/" to link_to ???

:trailing_slash

Re: how to add "/" to link_to ???

http://blogs.ugidotnet.org/CarlitoWaY/a … elper.aspx