Rails 6.1 form_with doesn't send PUT request

557 Views Asked by At

I added the method: patch to the form_with helper (like it said to in this SO post)

<%= form_with(model: [:admin, contest], method: :patch) do |form| %>
  ...

and the <input type="hidden" name="_method" value="patch"> shows up (like it's supposed to) but then when I click "Submit", the request is still a POST request and I get the error

No route matches [POST] "/admin/contests/7"
1

There are 1 best solutions below

2
On

I had the same issue, and resolved it by changing it to:

method: "patch"

Update: You're right, "patch" and :patch do the same. I also added the url from my routes file:

model#update

I think I need some more info. What does your controller look like? What model is it? Have you tried specifying the model and the url in form_with?