We've just upgraded our Rails 2.0.2 app to 2.3 and the webservices
create APIs are failing. Instead of receiving parsed XML, the
controller's create method gets the whole xml as a hash key with the
value nil.
To isolate this issue, I generated a vanilla app:
$ rails scaffold_xml
$ ./script/generate scaffold project title:string description:text
$ rake db:migrate
In real life I test this with cucumber features, but for the purposes of
short repro steps, I added this to the top of projects_controller.rb
skip_before_filter :verify_authenticity_token
And then ran the POST for the create request on the command line
$ curl -X POST -d '<project><title>Awesome</title><description>This is
an awesome project.</description>' http://localhost:3000/projects.xml
The log says:
Processing ProjectsController#create to xml (for 127.0.0.1 at 2009-06-21
07:09:08) [POST]
Parameters: {"<project><title>Awesome</title><description>This is an
awesome project.</description>"=>nil}
Project Create (10.4ms) INSERT INTO "projects" ("updated_at",
"title", "description", "created_at") VALUES('2009-06-21 14:09:08',
NULL, NULL, '2009-06-21 14:09:08')
Completed in 181ms (View: 134, DB: 10) | 201 Created
[http://localhost/projects.xml\]
To test my assumptions, I repeated the above steps with "rails _2.0.2_
scaffold_xml_202" to look at it in the old version of rails (minus the
forgery bit which didn't used to be required.) I must be missing
something basic here. Can anyone enlighten me or point me to relevant
docs?
To test my assumptions, I repeated the above steps with "rails _2.0.2_
scaffold_xml_202" to look at it in the old version of rails (minus the
forgery bit which didn't used to be required.)
Note: in Rails 2.0.2 it does the exact same thing, so I must need to do
something special to get the behavior I want, or some assumption I'm
making about the default webservices XML API behavior is incorrect.
We've just upgraded our Rails 2.0.2 app to 2.3 and the webservices
create APIs are failing. Instead of receiving parsed XML, the
controller's create method gets the whole xml as a hash key with the
value nil.
To isolate this issue, I generated a vanilla app:
$ rails scaffold_xml
$ ./script/generate scaffold project title:string description:text
$ rake db:migrate
In real life I test this with cucumber features, but for the purposes of
short repro steps, I added this to the top of projects_controller.rb
skip_before_filter :verify_authenticity_token
And then ran the POST for the create request on the command line
$ curl -X POST -d '<project><title>Awesome</title><description>This is
an awesome project.</description>'http://localhost:3000/projects.xml
I assume this is a typo and than in the real world you had remembered
the closing </project>. Having done that you need to get curl to set
the content type appropriately.
Frederick Cheung wrote:
> I assume this is a typo and than in the real world you had remembered
> the closing </project>. Having done that you need to get curl to set
> the content type appropriately.
I thought that posting to projects.xml would mean that setting the
content-type wasn't required (even though I am doing that in cucumber,
just cuz it seems like the right thing to do)
posting to .foo means that rails thinks you want .foo returned to you
(so you'll end up in your format.foo block if you're using
respond_to )
The content type of the data you are posting is a separate thing
(although it would probably be sensible if it did assume that posting
to .xml means that you're sending xml)