views:

194

answers:

2
echo '<request><item attribute="foo">bar</item></request>' | curl -X POST -H 'Content-type: application/xml' -d @- http://10.0.1.51:3000/baz/evaluate

My Rails application forgets all about the attribute when it receives the posted XML.

Processing BazController#evaluate (for 10.0.1.3 at 2009-10-03 18:29:32) [POST]
  Parameters: {"request"=>{"item"=>"bar"}}

Any idea what I'm doing wrong?

A: 

Hrm... I think this Rails ticket with its associated patch is relevant to this problem.

Brad Beattie
I think it probably is. Unfortunately as howardk notes in that discussion: "This is a fundamental problem in Rails -- Hash.from_xml just isn't very XML savvy."
Peter Wagenet
+1  A: 

Given that Hash.from_xml isn't very savvy you could try grabbing the raw XML before Rails messes with it. From the controller, you should be able to do request.raw_post. I think that will get you what you want, though there are other similar method that may be better suited. Once you get the raw XML then you can parse it yourself as necessary.

Peter Wagenet