Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set method put in form_tag in rails?

how to set method inside form to put in form_tag in rails?, i have form_tag like this :

<%= form_tag(url, :method => :put, :multipart => true, :class =>"form-horizontal") do %>
 ......
<% end %>

but if i inspect element, form not have method "put" but still "post"?

<form accept-charset="UTF-8" action="/admin/stores/1/information/social_update" class="form-horizontal" enctype="multipart/form-data" method="post">
 ....
</form>

why???

like image 389
tardjo Avatar asked Jan 10 '14 23:01

tardjo


1 Answers

According to 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.

Therefore, the following code will output the following markup:

form_tag('/posts/1', method: :put)
#=> <form action="/posts/1" method="post"> ... <input name="_method" type="hidden" value="put" /> ...

This is basically a backwards compatible way of implementing the PUT protocol across browsers. Although the form's submission method is POST, because of the hidden form input, Rails understands the desired submission method to be PUT.

like image 103
zeantsoi Avatar answered Oct 06 '22 03:10

zeantsoi