Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use underscores instead of dashes with ActiveResource XML (set :dasherize to false)

I am hitting all kinds of walls trying to stop rails from replacing XML underscores with dashes. I'm doing a post to a web service using ActiveResource. I have tried all kinds of variations of fixes for this, with results varying from rails initialization errors to just no effect. The web service I am posting to requires underscores.

Essentially, if I can get the following in place, I should be good:

From http://rubydoc.info/docs/rails/2.3.8/ActiveResource/Base

:dasherize - Boolean option to determine whether or not element names should replace underscores with dashes. Default is true. The default can be set to false by setting the module attribute ActiveSupport.dasherize_xml = false in an initializer.

Can someone provide an example of this? I'm unfortunately on a tight timeline, so if someone can provide assistance that would be a huge help.

Thanks!

like image 719
slimchrisp Avatar asked Mar 25 '11 21:03

slimchrisp


1 Answers

Did you attempt to set the module attribute to false in an initializer?

ActiveSupport.dasherize_xml = false

for rails 3+ you can use the following within your response:

render :xml => object.to_xml(:dasherize => false)

See edit history for ugly monkeypatching approach.

like image 139
20man Avatar answered Oct 20 '22 16:10

20man