class ActiveRecord::Errors

Add more extensive reporting on errors including field name along with a message when errors are serialized to XML and JSON

Public Instance Methods

to_amf(options = {}) click to toggle source

serialize errors to AMF

# File lib/restfulx/rx_active_record.rb, line 354
def to_amf(options = {})
  options[:amf_version] = 3
  options[:serializer] ||= RestfulX::AMF::RxAMFSerializer.new
  options[:serializer].serialize_errors(Hash[*@errors.to_a.flatten]).to_s
end
to_fxml(options = {}) click to toggle source

serializer errors to fXML

# File lib/restfulx/rx_active_record.rb, line 330
def to_fxml(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|
    # The @errors instance variable is a Hash inside the Errors class
    @errors.each do |attr, msg|
      next if msg.nil?
      if attr == "base"
        options[:builder].error("message", msg.to_s)
      else
        options[:builder].error("field" => attr.camelcase(:lower), "message" => msg.to_s)
      end
    end
  end
end
to_json(options = {}) click to toggle source

serialize errors to JSON

# File lib/restfulx/rx_active_record.rb, line 349
def to_json(options = {})
  "{#{'errors'.inspect}:#{to_json_original(options)}}"
end
Also aliased as: to_json_original
to_json_original(options = {}) click to toggle source
Alias for: to_json