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.

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.