method

to_xml

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveModel::Serializers::Xml

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v4.2.9) is shown here.

These similar methods exist in v7.1.3.2:

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

Show source
Register or log in to add new notes.