if I do this:
curl -X POST -H 'Content-type: application/xml' -d '<person>...</person>' 'http://0.0.0.0:3000/people/12?_method=PUT'
I get "Only get, put, and delete requests are allowed." Why? Rails 2.3.2
if I do this:
curl -X POST -H 'Content-type: application/xml' -d '<person>...</person>' 'http://0.0.0.0:3000/people/12?_method=PUT'
I get "Only get, put, and delete requests are allowed." Why? Rails 2.3.2
There's a couple of things that could be going wrong.
First off, you're sending a POST
with curl
, but you've got the "magic" _method
parameter on your URL, and it's set to PUT
. Based on the error, it sounds like Rails is taking POST
as the authoritative request type. Try it without that and see what happens.
On a more pedestrian error, the routing (in config/routes.rb
could be configured to not allow POST
requests for for the action you are attempting to use.
If you're using a standard RESTful controller, that makes good sense, because you're accessing a member (/people/12
) which by default only allows GET
, PUT
, and DELETE
.
I would try using curl -X PUT
and dropping the ?_method=PUT
from your request.
This is actually a malfunctioning in rails recent versions. The solution is to pass the HTTP method override header with put. Important:the full name of the header is http-x-http-method-override but rails adds the http prefix so you should trim that part.
luca is correct, you need to send the X-Http-Method-Override header with your request. Putting _method=put in the JSON body did not work for me. Your curl command line will look like this:
curl
-H "X-Http-Method-Override: put"
-H "Content-Type: application/json"
-d "{\"user\":{\"email\":\"[email protected]\"}}"
www.site.com/users/username.json