Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created March 11, 2010 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teeparham/329698 to your computer and use it in GitHub Desktop.
Save teeparham/329698 to your computer and use it in GitHub Desktop.
deserialize an array of ActiveRecord objects from xml
module ActiveRecord
class Base
# extends the patch here: http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/
def self.array_from_xml(xml)
hash_array = Hash.from_xml(xml).values.first
hash_array.nil? ? [] : hash_array.collect {|attributes_hash| from_hash(attributes_hash)}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment