Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_form delete method instead post method

In simple_form is possible to use the http delete verb instead the default post verb?

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

It doesn't works.

like image 606
user1066183 Avatar asked Dec 06 '22 03:12

user1066183


1 Answers

Unfortunately simply stating that it doesn't work is not helpful in understanding the problem you're seeing, but I'll make a guess based on my own initial confusion with the "method:" parameter. Most browsers don't support PUT and DELETE methods, so what simple_form_for does is generate a form with a POST method, but it 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 that to call the correct controller method. Hope that helps.

like image 94
user2665949 Avatar answered Dec 17 '22 09:12

user2665949