from_xml(xml)
Instance Public methods
Sets the model attributes
from an XML string. Returns
self
.
class Person include ActiveModel::Serializers::Xml attr_accessor :name, :age, :awesome def attributes=(hash) hash.each do |key, value| instance_variable_set("@#{key}", value) end end def attributes instance_values end end xml = { name: 'bob', age: 22, awesome:true }.to_xml person = Person.new person.from_xml(xml) # => #<Person:0x007fec5e3b3c40 @age=22, @awesome=true, @name="bob"> person.name # => "bob" person.age # => 22 person.awesome # => true
Please login to continue.