@@ -76,16 +76,56 @@ def from_xml(xml, save_cache = false)
7676 # Consider a Person resource on the server requiring both a +first_name+ and a +last_name+ with a
7777 # <tt>validates_presence_of :first_name, :last_name</tt> declaration in the model:
7878 #
79- # person = Person.new(: first_name => "Jim", : last_name => "")
79+ # person = Person.new(first_name: "Jim", last_name: "")
8080 # person.save # => false (server returns an HTTP 422 status code and errors)
8181 # person.valid? # => false
8282 # person.errors.empty? # => false
8383 # person.errors.count # => 1
8484 # person.errors.full_messages # => ["Last name can't be empty"]
85- # person.errors[:last_name] # => ["can't be empty"]
85+ # person.errors[:last_name] # => ["can't be empty"]
8686 # person.last_name = "Halpert"
8787 # person.save # => true (and person is now saved to the remote service)
8888 #
89+ # Consider a POST /people.json request that results in a 422 Unprocessable
90+ # Content response with the following +application/json+ body:
91+ #
92+ # {
93+ # "errors": {
94+ # "base": ["Something went wrong"],
95+ # "address": ["is invalid"]
96+ # }
97+ # }
98+ #
99+ # By default, Active Resource will automatically load errors from JSON response
100+ # objects that have a top-level +"errors"+ key that maps attribute names to arrays of
101+ # error message strings:
102+ #
103+ # person = Person.new(first_name: "Jim", last_name: "Halpert", address: "123 Fake Street")
104+ # person.save # => false (server returns an HTTP 422 status code and errors)
105+ # person.valid? # => false
106+ # person.errors[:base] # => ["Something went wrong"]
107+ # person.errors[:address] # => ["is invalid"]
108+ #
109+ # Consider a POST /people.xml request that results in a 422 Unprocessable
110+ # Content response with the following +application/xml+ body:
111+ #
112+ # <errors>
113+ # <error>Something went wrong</error>
114+ # <error>Address is invalid</error>
115+ # </errors>
116+ #
117+ # By default, Active Resource will automatically load errors from XML response
118+ # documents that have a top-level +<errors>+ element that contains +<error>+
119+ # children that have error message content. When an error message starts with
120+ # an attribute name, Active Resource will automatically infer that attribute
121+ # name and add the message to the attribute's errors. When an attribute name
122+ # cannot be inferred, the error message will be added to the +:base+ errors:
123+ #
124+ # person = Person.new(first_name: "Jim", last_name: "Halpert", address: "123 Fake Street")
125+ # person.save # => false (server returns an HTTP 422 status code and errors)
126+ # person.valid? # => false
127+ # person.errors[:base] # => ["Something went wrong"]
128+ # person.errors[:address] # => ["Address is invalid"]
89129 module Validations
90130 extend ActiveSupport ::Concern
91131 include ActiveModel ::Validations
0 commit comments