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:

JavaScript:
  1. new Ajax.Request(url, {
  2.                 onSuccess: callback,
  3.                 requestHeaders: {'X-Http-Method-Override': 'put'},
  4.                 postBody: Object.toJSON(params),
  5.                 contentType: "application/json"
  6.             });