This project is archived and is in readonly mode.

#3133 ✓stale

ActiveRecord::Serialization class method from_xml handles arrays and singleton XML instances

Reported by sbwoodside | September 2nd, 2009 @ 04:38 AM

I wanted a from_xml method for ActiveRecord that would be able to import data from XML that contained an array of objects as well as just a single object. Also, this should be a class method so it would instantiate the objects for me. The Gist at has my implementation. Is this worth submitting?

Comments and changes to this ticket

  • sbwoodside

    sbwoodside September 2nd, 2009 @ 09:48 PM

      module ActiveRecord::Serialization
        def self.from_xml(xml)
          the_class = Hash.from_xml(xml).keys.first.singularize.camelize.constantize # singularize does nothing if already singular
          array_or_hash = Hash.from_xml(xml).values.first
          array_or_hash.class == Array ? { |hash| hash ) } : array_or_hash )
  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 06:43 AM

    • State changed from “new” to “stale”
    • Importance changed from “” to “”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket


Referenced by