method

from_xml

Importance_2
v4.1.8 - Show latest stable - 0 notes - Class: ActiveModel::Serializers::Xml
from_xml(xml) public

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
Show source
Register or log in to add new notes.