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?
The
pathversion produces relative urls such as/order/34/lines/while the url version produces a full url such ashttp://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=>:postoption 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 asubmitcall to send your browser to the requested page with a post method.