I'm finding that XML and JSON serialization in Rails 2.3.5 don't seem to work the same. Has anyone encountered this and come up with a workaround?
class Record < ActiveRecord::Base
...
def my_method
{ :attribute1 => 'value1', :attribute2 => 'value2' }
end
...
end
@record.to_json(:method => [:my_method])
returns correct JSON where the attributes are nested correctly, as in
{'record':{'my-method':{'attribute1':'value1', 'attribute2':'value2'}}}
However
@record.to_xml(:method => [:my_method])
returns XML where the attributes and values are combined into a single string, such as the following:
<record>
<my-method>attribute1value1attribute2value2</my-method>
</record>