Forum: Ruby on Rails how to get root path with link_to ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E38fd7ebdb2c3e6816808b8da4eaf117?d=identicon&s=25 guillaume (Guest)
on 2008-10-24 20:48
(Received via mailing list)
Hi,

I would like to get the root path of my website using link_to in a
view... (for example : http://www.mywebsite/controller/action/id)
how is that possible ?

(i do need it, because i use the generated code in the view outside of
the rails app')

Thanks..
5acba71393125496e93b9e434d8b63c9?d=identicon&s=25 Sjoerd Andringa (s-andringa)
on 2008-10-25 19:01
guillaume wrote:
> Hi,
>
> I would like to get the root path of my website using link_to in a
> view... (for example : http://www.mywebsite/controller/action/id)
> how is that possible ?
>
> (i do need it, because i use the generated code in the view outside of
> the rails app')
>
> Thanks..

in routes.rb:
  map.root '/'

in your view:
  link_to 'link to root', root_url

Is that what you need?

-Sjoerd
84b661cb6bd8a870c1787968ee945962?d=identicon&s=25 Patrick Sullivan (ywp)
on 2008-10-25 19:23
(Received via mailing list)
Or you could just do this:

link_to "Link", "/"
5acba71393125496e93b9e434d8b63c9?d=identicon&s=25 Sjoerd Andringa (s-andringa)
on 2008-10-27 22:24
Patrick Sullivan wrote:
> Or you could just do this:
>
> link_to "Link", "/"

True, however won't that just generate a relative url? So <a
href="/">Link</a> instead of <a href="http://www.mysite.com/">Link</a>?
I believe Guillaume requires the latter, as his views are also used
outside of his app.
This topic is locked and can not be replied to.