I want to generate links, but I want the links to use the full path of the URL, not the relative path. link_to( "click here", :controller => ''foo'', :action => ''bar'' ) => <a href="/foo/bar">click here</a> But I want: link_to( "click here", :controller => ''foo'', :action => ''bar'' ) => <a href="http://www.mydomain.com/foo/bar">click here</a> I know one can get the full url by using url_for(), but that doesn''t actually create the hyperlink. Obviuosly, one could do: <a href="<%= url_for( :controller => ''foo'', :action => ''bar'' ) %>">click here</a> But that seems cludgy and doesn''t fit into the "Rails Way". It seems like there should be an option to pass to link_to to do this instead... anyone know of a method to accomplish this?
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Jul-20 16:18 UTC
Re: link_to full path
Hi ! Belorion said the following on 2005-07-20 12:15:> I know one can get the full url by using url_for(), but that doesn''t > actually create the hyperlink. Obviuosly, one could do: > > <a href="<%= url_for( :controller => ''foo'', :action => ''bar'' ) > %>">click here</a> > > But that seems cludgy and doesn''t fit into the "Rails Way". It seems > like there should be an option to pass to link_to to do this > instead... anyone know of a method to accomplish this?You''re almost there :) <%= link_to ''click here'', url_for(:controller => ''foo'', :action => ''bar'') %> Hope that helps ! François
Try the :only_path option: <%= link_to ''click here'', :controller => ''foo'', :action => ''bar'', :only_path = false %> http://rails.rubyonrails.com/classes/ActionController/Base.html#M000170 On 7/20/05, Belorion <belorion-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to generate links, but I want the links to use the full path of > the URL, not the relative path. > > link_to( "click here", :controller => ''foo'', :action => ''bar'' ) > => <a href="/foo/bar">click here</a> > > But I want: > > link_to( "click here", :controller => ''foo'', :action => ''bar'' ) > => <a href="http://www.mydomain.com/foo/bar">click here</a> > > I know one can get the full url by using url_for(), but that doesn''t > actually create the hyperlink. Obviuosly, one could do: > > <a href="<%= url_for( :controller => ''foo'', :action => ''bar'' ) > %>">click here</a> > > But that seems cludgy and doesn''t fit into the "Rails Way". It seems > like there should be an option to pass to link_to to do this > instead... anyone know of a method to accomplish this? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- rick http://techno-weenie.net
Actually, I think it might be: :only_path = true The docs say: ":only_path — if true, returns the absolute URL (omitting the protocol, host name, and port)" HTH! On 7/20/05, Rick Olson <technoweenie@gmail.com> wrote:> Try the :only_path option: > > <%= link_to 'click here', :controller => 'foo', :action => 'bar', > :only_path = false %> > > http://rails.rubyonrails.com/classes/ActionController/Base.html#M000170 > > On 7/20/05, Belorion <belorion@gmail.com> wrote: > > I want to generate links, but I want the links to use the full path of > > the URL, not the relative path. > > > > link_to( "click here", :controller => 'foo', :action => 'bar' ) > > => <a href="/foo/bar">click here</a> > > > > But I want: > > > > link_to( "click here", :controller => 'foo', :action => 'bar' ) > > => <a href="http://www.mydomain.com/foo/bar">click here</a> > > > > I know one can get the full url by using url_for(), but that doesn't > > actually create the hyperlink. Obviuosly, one could do: > > > > <a href="<%= url_for( :controller => 'foo', :action => 'bar' ) > > %>">click here</a> > > > > But that seems cludgy and doesn't fit into the "Rails Way". It seems > > like there should be an option to pass to link_to to do this > > instead... anyone know of a method to accomplish this? > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Frank FrankManno.com <a href="http://www.spreadfirefox.com/?q=affiliates&id=2496&t=1">Get Firefox!</a> _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> I think it might be: > > :only_path = true > > The docs say: > > ":only_path — if true, returns the absolute URL (omitting the > protocol, host name, and port)"Hmm, so it does. Does that seem backwards to anyone else? I would think :only_path would show only the path and not the whole url. I'm actually using it in this way to set domains for my app that uses the subdomain-as-account-key pattern. -- rick http://techno-weenie.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 7/20/05, Rick Olson <technoweenie@gmail.com> wrote:> > I think it might be: > > > > :only_path = true > > > > The docs say: > > > > ":only_path — if true, returns the absolute URL (omitting the > > protocol, host name, and port)" > > Hmm, so it does. Does that seem backwards to anyone else? I would > think :only_path would show only the path and not the whole url. I'm > actually using it in this way to set domains for my app that uses the > subdomain-as-account-key pattern.That makes sense to me -- you're asking it for _only the path_, which is to say "the absolute URL (omitting the protocol, host name, and port)". If it included the protocol, host name, and port, then it would be the whole URL, not only the path. Right? I think... -- Chris Boone http://hypsometry.com/ : website edification http://uvlist.org/ : free classifieds for the Upper Valley _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails