Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails :method=>:patch doesn't work

So, I have this form declaration:

<%= form_for 'students_list', {:url => update_students_list_stream_url(@stream), :method=>:patch}  do |students_list_form| %>

Just as described in API docs, but this leads me to error:

No route matches [POST] "/streams/26/edit-students-list"

So it still tries to post, even though my HTML input has:

<input type="hidden" name="_method" value="patch" />

From Rails guide:

Rails works around this issue by emulating other methods over POST with a hidden input named "_method", which is set to reflect the desired method:

I'm quite confused

like image 236
Joe Half Face Avatar asked Dec 12 '15 23:12

Joe Half Face


1 Answers

I was looking for an answer on why rails loaded method patch as post in the rendered form. If you ended up here looking for that like I did, this is the answer you are looking for:

https://stackoverflow.com/a/46699512/5750078

From https://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-patch-put-or-delete-methods-work-questionmark:

enter image description here

like image 151
Alvaro Rodriguez Scelza Avatar answered Sep 30 '22 03:09

Alvaro Rodriguez Scelza