1

This may be a basic question but it has been causing me some problems. I am trying to dump an ActiveRecord Object to an XML file using the to_xml function. For whatever reason, this does not work for me if I try to nest it into an element. Basically I have a hash of ActiveRecord objects that I want to iterate over, and then dump into my XML file like this:

@hash_of_activerecord.each do |key, value|
    xml.object do
      value.to_xml
    end
end

For whatever reason this does not seem to work. What can I do to fix it? Obviously I could just print out each aspect of the object individually but that is not the best solution because I would have to remember to change what is in that loop if I later made a change to the contents of that ActiveRecord object.

Rhawb
  • 53
  • 1
  • 8

1 Answers1

0

Use :include. See http://apidock.com/rails/ActiveRecord/Serialization/to_xml

xyz
  • 1,513
  • 2
  • 13
  • 17
  • This wouldn't allow for me to print out multiple different hashes on one XML file would it? It seems like Builder basically wants just one line to generate the XML file. I want to print multiple hashes into one XML file, along with things that are not hashes. – Rhawb Mar 14 '12 at 21:57