开发者

the method problem and the difference between url and path

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 th开发者_StackOverflow社区e code doesn't has the method like :method=>:post,

why?


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.


The _url helper generates an URL that includes the protocol and host name. The _path helper generates only the path portion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜