i am using link_to to make links. it is gnerating urls relative to the path of the page. how do i make absolute urls. i tried using only_path but it does nto seem to work. do i need to use url_for? thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Mar 1, 2009 at 5:21 AM, tashfeen.ekram <tashfeen.ekram-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > i am using link_to to make links. it is gnerating urls relative to the > path of the page. how do i make absolute urls. i tried using only_path > but it does nto seem to work.When you are e.g. in http://www.mysite.com/test/sub/hello (controller: ''test/sub'' ; action: ''hello'') and want to link to: http://www.mysite.com/home (controller: ''home'' ; action: ''index'') One way to do it is to use: link_to ''home'', ''/home'' this results in: <a href="/home">Home</a> (which is relative to root (''/'')) using: link_to ''home'', ''home'' results in: <a href="home">Home</a> (which the browser translates into http://www/mysite.com/test/sub/home and is not what I wanted) If you want to use it with a reference to the /home controller, use: link_to ''Home'', :controller => ''/home'' From the api.rubyonrails.org documentation for url_for : ++++ If the controller name begins with a slash no defaults are used: url_for :controller => ''/home'' In particular, a leading slash ensures no namespace is assumed. Thus, while url_for :controller => ‘users‘ may resolve to Admin::UsersController if the current controller lives under that module, url_for :controller => ’/users‘ ensures you link to ::UsersController no matter what. ++++ HTH, Peter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 1, 5:21 am, "tashfeen.ekram" <tashfeen.ek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i am using link_to to make links. it is gnerating urls relative to the > path of the page. how do i make absolute urls. i tried using only_path > but it does nto seem to work.A few ways that work for me are: link_to ''Home'', ''/home'' # => <a href=''/home''>Home</a> link_to ''Home'', ''http://www.mysite.com/home'' # => <a href=''http:// www.mysite.com/home''>Home</a> link_to ''Home'', :controller => ''/home'' # note the ''/'' in front of home <a href=''/home''>Home</a>> do i need to use url_for?link_to already uses url_for if I understand well. only_path is used to make URL''s relative to the root (first ''/'') of this URL. Is useful when behind a proxy (e.g. an SSL proxy). Much more info can be found on http://api.rubyonrails.org searching the method: url_for (ActionController::Base) HTH, Peter --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---