Flex & Rails: REST Fix

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.

no comments | atom

Comments

Leave a response

Leave a comment