如何在form中设置方法以将form_tag放入rails?中,我有这样的form_tag:
<%= form_tag(url,:method => :put,:multipart => true,:class =>"form-horizontal") do %> ...... <% end %>
但如果我检查元素,形式没有方法“放”但仍然“发布”?
<form accept-charset="UTF-8" action="/admin/stores/1/information/social_update" class="form-horizontal" enctype="multipart/form-data" method="post"> .... </form>
为什么???
解决方法
根据
the docs:
If “patch”,“put”,“delete”,or another verb is used,a hidden input with name _method is added to simulate the verb over post.
form_tag('/posts/1',method: :put) #=> <form action="/posts/1" method="post"> ... <input name="_method" type="hidden" value="put" /> ...
这基本上是跨浏览器实现PUT协议的向后兼容方式.虽然表单的提交方法是POST,但由于隐藏表单输入,Rails了解所需的提交方法是PUT.