tags:

views:

88

answers:

3

I have this in Flex:

<mx:HTTPService id="update"
 url="http://localhost:3000/people/{grid.selectedItem.id}.xml?_method=put" 
 contentType="application/xml"
 resultFormat="e4x"
 method="POST"
 result="index.send()"/>

And when it fires I get the following error in Rails:

Processing ApplicationController#index (for 127.0.0.1 at 2009-12-07 05:33:55) [POST]
  Parameters: {"person"=>{"first_name"=>"Paul", "last_name"=>"Goulart"}}

ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.):
  -e:2:in `load'
  -e:2

If I edit the same record using scaffolding provided by rails it works:

Processing PeopleController#update (for 127.0.0.1 at 2009-12-07 05:37:08) [PUT]
  Parameters: {"commit"=>"Update", "authenticity_token"=>"MV9lFxBGxPgqP0WRTqEWa9/8D36ZzX9opk0SzJ3hUjA=", "id"=>"2", "person"=>{"first_name"=>"Paul", "address"=>"San Francisco", "last_name"=>"Goulart"}}
  [4;35;1mPerson Columns (8.0ms)[0m   [0mSHOW FIELDS FROM `people`[0m
  [4;36;1mPerson Load (0.0ms)[0m   [0;1mSELECT * FROM `people` WHERE (`people`.`id` = 2) [0m
  [4;35;1mSQL (0.0ms)[0m   [0mBEGIN[0m
  [4;36;1mPerson Update (0.0ms)[0m   [0;1mUPDATE `people` SET `first_name` = 'Paul', `updated_at` = '2009-12-07 13:37:08' WHERE `id` = 2[0m
  [4;35;1mSQL (1.0ms)[0m   [0mCOMMIT[0m

This should be an easy thing. Just trying to update data from flex using xml.

I'm stuck. Can anyone help?

Thanks.

Paul

A: 

I think you need to post _method parameter. It isn't accepting the _GET for the method parameter, and returning that only GET, PUT, and DELETE requests are allowed for this route.

CodeJoust
A: 

Only get, put, and delete requests are allowed.

change method="POST" to method="PUT" or method="GET"

<mx:HTTPService id="update"
 url="http://localhost:3000/people/{grid.selectedItem.id}.xml?_method=put" 
 contentType="application/xml"
 resultFormat="e4x"
 method="GET"
 result="index.send()"/>

HTTPService supports GET, POST, HEAD, OPTIONS, PUT, TRACE and DELETE methods.

Amarghosh
for some reason that didn't work either, it still thinks I'm sending a post. By the way the result="update.send()"If anyone can help me with this I would really appreciate it or better yet if someone has an example of simple CRUD using RubyAMF or simple REST that would be so helpful.Do I have to do something in routes to make it accept the update? I'm so frustrated.
Paul
A: 
Paul