Skip to content

Commit

Permalink
Corrected documentation regarding validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zduci committed May 16, 2013
1 parent 8f901de commit 5554775
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions guides/source/active_record_validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ Person.create(name: nil).valid? # => false
```

After Active Record has performed validations, any errors found can be accessed
through the `errors` instance method, which returns a collection of errors. By
definition, an object is valid if this collection is empty after running
through the `errors.messages` instance method, which returns a collection of errors.
By definition, an object is valid if this collection is empty after running
validations.

Note that an object instantiated with `new` will not report errors even if it's
Expand All @@ -176,17 +176,17 @@ end

>> p = Person.new
#=> #<Person id: nil, name: nil>
>> p.errors
>> p.errors.messages
#=> {}

>> p.valid?
#=> false
>> p.errors
>> p.errors.messages
#=> {name:["can't be blank"]}

>> p = Person.create
#=> #<Person id: nil, name: nil>
>> p.errors
>> p.errors.messages
#=> {name:["can't be blank"]}

>> p.save
Expand Down Expand Up @@ -993,12 +993,12 @@ end

person = Person.new
person.valid? # => false
person.errors
person.errors.messages
# => {:name=>["can't be blank", "is too short (minimum is 3 characters)"]}

person = Person.new(name: "John Doe")
person.valid? # => true
person.errors # => []
person.errors.messages # => {}
```

### `errors[]`
Expand Down

0 comments on commit 5554775

Please sign in to comment.