Skip to content

_method in recent rails is brokenish

by Topper on February 28th, 2010

I was trying to pass in _method: ‘put’ as part of a json body and for some reason rails kept not realizing that I wanted to put.

Then I came across this article: http://stackoverflow.com/questions/1249282/set-method-to-put-in-rails-xml-requests

So… if you’re using prototype your “put” methods look something like this:

[js]
new Ajax.Request(url, {
onSuccess: callback,
requestHeaders: {‘X-Http-Method-Override’: ‘put’},
postBody: Object.toJSON(params),
contentType: “application/json”
});
[/js]