Module: ActiveModel::Serializers::Xml
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Serialization
- Defined in:
- lib/active_model/serializers/xml.rb
Overview
Active Model XML Serializer
Defined Under Namespace
Classes: Serializer
Instance Method Summary collapse
- #from_xml(xml) ⇒ Object
-
#to_xml(options = {}, &block) ⇒ Object
Returns XML representing the model.
Methods included from ActiveModel::Serialization
Instance Method Details
#from_xml(xml) ⇒ Object
198 199 200 201 |
# File 'lib/active_model/serializers/xml.rb', line 198 def from_xml(xml) self.attributes = Hash.from_xml(xml).values.first self end |
#to_xml(options = {}, &block) ⇒ Object
Returns XML representing the model. Configuration can be
passed through options.
Without any options, the returned XML string will include all the model's
attributes. For example:
user = User.find(1)
user.to_xml
The :only and :except options can be used to limit the attributes
included, and work similar to the attributes method.
To include the result of some method calls on the model use :methods.
To include associations use :include.
For further documentation see activerecord/lib/active_record/serializers/xml_serializer.xml.
194 195 196 |
# File 'lib/active_model/serializers/xml.rb', line 194 def to_xml( = {}, &block) Serializer.new(self, ).serialize(&block) end |