public Method

Errors.from_xml(xml)

Grabs errors from the XML response.

Source Code

# File active_resource/validations.rb, line 203
def from_xml(xml)
  clear
  humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) }
  messages = Hash.from_xml(xml)['errors']['error'] rescue []
  messages.each do |message|
    attr_message = humanized_attributes.keys.detect do |attr_name|
      if message[0, attr_name.size + 1] == "#{attr_name} "
        add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
      end
    end

    add_to_base message if attr_message.nil?
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.