0

I am trying to create a Javascript-free app (don't ask why...) and have run into the apparently common problem of the :delete method not working.

I found this question which told me I have to use Plug.MethodOverride.

So, I have added

plug Plug.Parser, parsers [:urlencoded, :multipart]
plug Plug.MethodOverride

to the Html pipeline in routers.ex (I am guessing I should probably move it to somewhere more specific later, but for now, I just wanted it to work quickly). However, the form generated by the resources helper still does not do anything. Do I have to change it to something else? Or am I missing a step in adding the Plug

Community
  • 1
  • 1
Igor K
  • 33
  • 6
  • 1
    Have you added the `method: :delete` to `form_for` as mentioned in an answer in that question: http://stackoverflow.com/a/36273932/320615? – Dogbert May 04 '16 at 12:53
  • Thanks, this pointed me into the right direction, I had been confused since I did not know link_to generates a form_for underneath. do you mind me posting the exact thing I did as an answer and accepting it for other complete newbies like me? – Igor K May 05 '16 at 19:05

1 Answers1

0

thanks @Dogbert for pointing me in the right direction in the docs, I had not understood that link_to has an underlying form_for. To make it work I replaced the <% link_to ..%> by the following code

<%= form_for @conn, model_path(@conn, :delete, model), [multipart: true, method: "delete", as: :custom_delete], fn f -> %>
    <%= submit "Delete_nojs" %>
<% end %>

with

plug Plug.Parser, parsers [:urlencoded, :multipart]
plug Plug.MethodOverride

in the router pipeline this enables the method override.

Igor K
  • 33
  • 6