Delete_form method instead of post method

In simple_form can the verb http delete be used instead of the standard post-verb?

<%= simple_form_for @object , method: :delete do |f| %>
    <%= f.input :instance_name, as: :check_boxes, collection: @roles  %>
    <%= f.button :submit %>
<% end %>

This does not work.

+4
source share
1 answer

Unfortunately, simply stating that it does not work does not help to understand the problem you are seeing, but I will make an assumption based on my own initial confusion with the "method:" parameter. Most browsers do not support the PUT and DELETE methods, therefore, that simple_form_for creates the form using the POST method, but also adds a hidden field to pass the actual method. So:

simple_form_for @service, url: service_path, method: :delete

generates:

<form action="/services/6" method="post">
  <input name="_method" type="hidden" value="delete" />
....

Rails uses this to invoke the correct controller method. Hope this helps.

+13

Source: https://habr.com/ru/post/1525616/


All Articles