Hello everyone, what''s the real difference between root_url and root_path in Rails, for example. Apparently both lead to the same route in the application. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
My understanding is that one is a full url, the other is a path. Generally you''d use a path, but if you are sending an email or doing something else that needs a full URL, you''d use the _url. Best Wishes, Peter On Feb 15, 2011, at 4:05 PM, Rodrigo Alves Vieira wrote:> Hello everyone, what''s the real difference between root_url and root_path in Rails, for example. Apparently both lead to the same route in the application. > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 February 2011 21:05, Rodrigo Alves Vieira <rodrigo3n-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everyone, what''s the real difference between root_url and root_path in > Rails, for example. Apparently both lead to the same route in the > application.They are both methods that return a string so it is easy to find out. <%= "root_path = #{root_path}, root_url = #{root_url}" %> Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi there, With *_url you''ll get the full path with protocol and domain name. Use it for redirect method for example, or when you redirecting for total different domain. With *_path you will get the part from your path which is after ''/'' without domain and stuff. Use it every other situation I think. With redirecting _path will also work fine, just later it can cause problems when you need to refactor your code. And an easy link_to can be used with _url, but it fills your HTML unnecessary characters, which also not a good idea. Check both, see the source of your HTML and you will see easily the diff. good luck, gezope On febr. 15, 22:05, Rodrigo Alves Vieira <rodrig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everyone, what''s the real difference between root_url and root_path in > Rails, for example. Apparently both lead to the same route in the > application. > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you guys. I checked it out and it makes total sense. Cheers! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
One other thing to look at is using _url whenever you need to cross the secure / non-secure bridge (either way). Also, any time you are inside JavaScript (Ajax) requests, be sure to use _path, otherwise you may trigger a same origin policy error in browsers that care about security. Walter On Feb 16, 2011, at 8:58 AM, Rodrigo Alves Vieira wrote:> Thank you guys. I checked it out and it makes total sense. > > Cheers! > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > .-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.