willard
willard

Reputation: 251

Use ActiveRecord's to_xml method, but camelize with first letter as lowercase

Is there a way to camelize with the first letter as lowercase when using active record's to_xml method? I know you can do this on a string by calling "hello_world".camelize(:lower), but the only option offered by the to_xml method is :camelize => true

Is there a way to do this using the delivered options? I've been reading that you can create your own xml builder, but I'm not sure where to start with that.

Any help would be greatly appreciated.

Upvotes: 0

Views: 255

Answers (1)

Chris Salzberg
Chris Salzberg

Reputation: 27374

Just replace true with :lower:

{ "hello_world" => 1 }.to_xml(:camelize => :lower)
#=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <helloWorld type=\"integer\">1</helloWorld>\n</hash>\n"

Upvotes: 3

Related Questions