instance method to_xml

Ruby on Rails 4.2.9

Since v3.0.20 Last seen in v4.2.9

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9

Signature

to_xml(options = {}, &block)

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.

user = User.find(1)
user.to_xml

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id type="integer">1</id>
  <name>David</name>
  <age type="integer">16</age>
  <created-at type="dateTime">2011-01-30T22:29:23Z</created-at>
</user>

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::Serialization#to_xml

Parameters

options opt = {}
block block
Source
# File activemodel/lib/active_model/serializers/xml.rb, line 204
      def to_xml(options = {}, &block)
        Serializer.new(self, options).serialize(&block)
      end

Defined in activemodel/lib/active_model/serializers/xml.rb line 204 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::Serializers::Xml

Type at least 2 characters to search.

↑↓ navigate · open · esc close