PUT 方法 form_for [英] PUT method form_for
问题描述
我正在使用以下内容尝试在表单上设置 PUT 方法,但它仍在发布.我已经参考了文档,看来我做对了.
I am using the following to try and set a PUT method on the form but it is still doing a post. I have referred to the docs and it seems like im doing this right.
form_for @firm, html: {autocomplete: "off"}, url: firm_path, method: :put do |f|
...
推荐答案
这样做是因为浏览器对 PUT
/DELETE
的支持不是很好.您可以在 Rails 指南:
It does this because browsers don't support PUT
/DELETE
very well. You can read more about this in the Rails Guides:
然而,大多数浏览器不支持除GET"和提交表单时的POST".
However, most browsers don’t support methods other than "GET" and "POST" when it comes to submitting forms.
Rails 通过在 POST 上模拟其他方法来解决这个问题带有一个名为 "_method"
的隐藏输入,它被设置为反映想要的方法.
Rails works around this issue by emulating other methods over POST
with a hidden input named "_method"
, which is set to reflect the
desired method.
这篇关于PUT 方法 form_for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!