When we define routes in routes.rb
using the name like map.some_link
.We can use the link in two ways- some_link_url
, some_link_path
.
A route can be part of a path when only a section of the path is actually traveled. A path is always physical available and may end in a rather unclear manner (e.g A footpath in a forest that blurs away). One or more paths can be part of a route.
Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.
Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.
I had the same question and I wrote a small post about this in my blog
The reason is summarized here (I found this on a forum):
*_path are for views because ahrefs are implicitly linked to the current URL. So it’d be a waste of bytes to repeat it over and over. In the controller, though, *_url is needed for redirect_to because the HTTP specification mandates that the Location: header in 3xx redirects is a complete URL.
Here is another explanation which says it depends on whether we need to use an absolute URI when linking to an SSL site from a non-SSL site, and vice versa.
What I have read so far, doesn't suggest that any of them is more secure than the other. It really comes down to what is the "proper" usage.
path
is relative while url
is absolute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With