I started getting exceptions like this without really being sure why:
ActionController::MethodNotAllowed
(Only get, put, and delete requests are allowed.)
I think the version of Rails was probably updated and it became less forgiving of our pitiful custom form builder.
One of the frustrating things about custom form builders is the Rails form helpers seems to move faster than it's practical to keep up with. So you end up with a whole lot of old-fashioned form builder code lying around that is either bigger than it needs to be or totally broken.
The new Rails RESTful routes stuff uses the "put" method to update existing records. Which I think is slightly silly, but someone is convinced we need to apply the HTTP CRUD metaphor to web forms. So we use hacks like <input type="hidden" name="_method" value="put" />
because forms don't support proper HTTP puts.
But anyway, that's the way things are and as everyone learns with Rails, resistance is futile or at least far more pain than it's worth.
But this particular problem I've fixed. The form action for updates should be /object/1234
, which accepts GET, PUT, DELETE. I was getting MethodNotAllowed errors because my form builder wasn't adding the hidden _method
field. Rails was treating the update as a normal POST to /object/1234
instead of a PUT. So I got the form builder to add in the hidden field for existing records, and everything was sweet.
Someone else had the same problem for a different reason.
Thank you !
With this post resolved my MethodNotAllowed error.
Ale / 5:28am / 31 August 2009