views:

31

answers:

1

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>
A: 

returns XML where the attributes and values are combined into a single string.

show all XML plz

Falcon
This is a comment, not an answer. Please delete this answer and resubmit it as a comment to the question instead.
Dolph
I updated with a better description of the XML. I'm referring to XML that looks like this: <record> <my-method>attribute1value1attribute2value2</my-method> </record>
steven