This project is archived and is in readonly mode.
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 http://gist.github.com/179530 has my implementation. Is this worth submitting?
Comments and changes to this ticket
-
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 ? array_or_hash.map { |hash| the_class.new( hash ) } : the_class.new( array_or_hash ) end end
-
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Tags
Referenced by
- 1598 Preserve XML Attributes with Hash#from_xml and ActiveResource Slightly related is that current implementation can't dea...