Haml:link_to vs button_to [英] Haml: link_to vs button_to

查看:118
本文介绍了Haml:link_to vs button_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解, link_to 用于get方法, button_to 用于post方法。

From what I understand, link_to is used for get methods, and button_to is used for post methods.

另一方面,我被告知使用HTML5语义,< button> 用于任何类型可点击的......好吧,按钮。如果我有一个可点击的按钮,将用户发送到表单填写,我应该创建 button_to 还是 link_to

On the other hand, I was told that with HTML5 semantics, <button> is used for any type of clickable...well, button. In the case I have a clickable button that sends a user to a form to fill out, should I create a button_to or a link_to?

推荐答案

您认为这更简单。
那些方法是Rails助手,与haml没有任何关系。
是的,一种方法是get,另一种方法是post方法。如果您需要将任何数据发布到控制器,请使用 button_to (例如,删除记录时)。否则, link_to 就足够了。

It's simpler that you think. That methods are Rails helpers and don't have anything to do with haml. Yes, one method is for get and another for post methods. If you need to post any data to controller, use button_to (for example when deleting a record). Otherwise, link_to is enough.

此外,你可以使 link_to 使用发布数据:方法参数:

Moreover, you can make link_to posting data using :method parameter:

= link_to "Something", some_path, :method => :post

回答你的问题,使用 link_to

Answering your question, use link_to.

这篇关于Haml:link_to vs button_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆