Reputation: 237
when i read the book "Aglie web development with rails 4th",i found the code
<%= button_to 'Add to Cart', line_items_path(:product_id => product) %>
what's the difference if i use "line_items_url"
and the code doesn't has the method like :method=>:post
,
why?
Upvotes: 0
Views: 289
Reputation: 19176
The path
version produces relative urls such as /order/34/lines/
while the url version produces a full url such as http://localhost:3000/order/34/lines/
.
The second form is often used in mailers when the user click a link in a mail client or in an external webmail.
In your site you won't notice any difference.
Moreover the :method=>:post
option will produce a post request to your webserver. It will do that by adding a javascript code which will create a form on the fly, add parameters to it and do a submit
call to send your browser to the requested page with a post method.
Upvotes: 4
Reputation: 5095
The _url
helper generates an URL that includes the protocol and host
name. The _path
helper generates only the path portion.
Upvotes: 0