instance method
to_xml
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
to_xml(options={})
Returns an XML representation of this error object.
class Company < ActiveRecord::Base validates_presence_of :name, :address, :email validates_length_of :name, :in => 5..30 end company = Company.create(:address => '123 First St.') company.errors.to_xml # => <?xml version="1.0" encoding="UTF-8"?> # <errors> # <error>Name is too short (minimum is 5 characters)</error> # <error>Name can't be blank</error> # <error>Address can't be blank</error> # </errors>
Parameters
-
optionsopt = {}
Source
# File activerecord/lib/active_record/validations.rb, line 248
def to_xml(options={})
options[:root] ||= "errors"
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
options[:builder].instruct! unless options.delete(:skip_instruct)
options[:builder].errors do |e|
full_messages.each { |msg| e.error(msg) }
end
end
Defined in activerecord/lib/active_record/validations.rb line 248
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Errors