Flex & Rails: REST Fix 3

Posted by Kristofer Joseph Sun, 10 Jan 2010 07:34:01 GMT

Before Rails 2.3.1 you could send a PUT request with application/xml contentType by appending ?_method=put to your HTTPServices url parameter. Unfortunately this stopped working. You can accomplish the same thing by sending a custom header of #X-Http-Method-Override# and setting it to PUT, or DELETE.

Example

If you have an update HTTPService like so:

<mx:HTTPService id="updateThing"
                resultFormat="e4x"
                url="http://localhost:3000/thing/{dataGrid.selectedItem.id}.xml"
                contentType="application/xml"
                method="POST"
                result="index.send()" />

You would add your custom header like this:

    /**
    * @private
    */
   protected function update_thing():void
   {
        var thing:XML = new XML(_thingXMLTemplate);
        thing['first-name'] = firstNameInput.text;
        thing['last-name'] = lastNameInput.text;
        var headers:Object = new Object();
        headers['X-Http-Method-Override'] = "PUT";
        updatePerson.headers = headers;
        updatePerson.send(thing);
   }

*Note the headers['X-Http-Method-Override']

Same goes for sending a DELETE. Hope this helps.

Comments

Leave a comment

  1. linux about 1 year later:

    I think this is one of the most important information for me. And i’m glad reading your article. But wanna remark on few general things, The website style is great, the articles is really excellent. Good job, cheers

  2. susan about 1 year later:

    Very Cheap Pro Cycling Online Shop www.bike-jersey.net for Cycling Jerseys.They have great quality and very cheap price ,also could offer the great service and fast shipping!!!

  3. best sleep aid about 1 year later:

    It is not hard to understand why the question of value is still raised when you consider that today�s outsourcing models have some inherent limitations that reduce the overall gains companies can achieve .

Comments