method
to_xml
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: ActiveModel::Serializers::Xml
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (35)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-2)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
to_xml(options = {}, &block)
public
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