Ruby-on-rails PUT 方法 form_for
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9551330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PUT method form_for
提问by Jason Waldrip
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.
我正在使用以下内容尝试在表单上设置 PUT 方法,但它仍在发布。我已经参考了文档,似乎我做对了。
form_for @firm, html: {autocomplete: "off"}, url: firm_path, method: :put do |f|
...
回答by Andrew Marshall
It does this because browsers don't support PUT/DELETEvery well. You can read more about this in the Rails Guides:
这样做是因为浏览器不支持PUT/DELETE很好。您可以在Rails 指南中阅读更多相关信息:
However, most browsers don't supportmethods other than “GET” and “POST” when it comes to submitting forms.
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.
但是,大多数浏览器在提交表单时不支持“GET”和“POST”以外的方法。
Rails 通过使用名为 的隐藏输入模拟 POST 上的其他方法来解决此问题
"_method",该输入设置为反映所需的方法。

