Haml:link_to 与 button_to [英] Haml: link_to vs button_to
问题描述
据我所知,link_to
用于获取方法,button_to
用于发布方法.
From what I understand, link_to
is used for get methods, and button_to
is used for post methods.
另一方面,有人告诉我,在 HTML5 语义中, 可用于任何类型的可点击……嗯,按钮.如果我有一个可点击的按钮,将用户发送到一个表单来填写,我应该创建一个
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.
此外,您可以使用 :method
参数制作 link_to
发布数据:
Moreover, you can make link_to
posting data using :method
parameter:
= link_to "Something", some_path, :method => :post
回答你的问题,使用link_to
.
这篇关于Haml:link_to 与 button_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!