aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_record_validations.md
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2015-02-15 12:30:38 +0100
committerRobin Dupret <robin.dupret@gmail.com>2015-02-15 19:19:04 +0100
commit1747c4e2cea811cbf04fccc9f57256c80112d9ce (patch)
treee0ea6f1b8dedbe206f15b67a9b226618539fc764 /guides/source/active_record_validations.md
parent3960908f41ea638556493762937c440761af9a65 (diff)
downloadrails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.tar.gz
rails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.tar.bz2
rails-1747c4e2cea811cbf04fccc9f57256c80112d9ce.zip
Tiny documentation edits [ci skip]
Diffstat (limited to 'guides/source/active_record_validations.md')
-rw-r--r--guides/source/active_record_validations.md47
1 files changed, 24 insertions, 23 deletions
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md
index 67cc6a4db3..93f76d3bf7 100644
--- a/guides/source/active_record_validations.md
+++ b/guides/source/active_record_validations.md
@@ -231,9 +231,9 @@ Errors](#working-with-validation-errors) section.
### `errors.details`
-To check what validator type was used on invalid attribute, you can use
-`errors.details[:attribute]`. It returns array of hashes where under `:error`
- key you will find symbol of used validator.
+To check which validations failed on an invalid attribute, you can use
+`errors.details[:attribute]`. It returns an array of hashes with an `:error`
+key to get the symbol of the validator:
```ruby
class Person < ActiveRecord::Base
@@ -245,7 +245,7 @@ end
>> person.errors.details[:name] #=> [{error: :blank}]
```
-Using `details` with custom validators are covered in the [Working with
+Using `details` with custom validators is covered in the [Working with
Validation Errors](#working-with-validation-errors) section.
Validation Helpers
@@ -1094,39 +1094,40 @@ Another way to do this is using `[]=` setter
### `errors.details`
-You can add validator type to details hash when using `errors.add` method.
+You can specify a validator type to the returned error details hash using the
+`errors.add` method.
```ruby
- class Person < ActiveRecord::Base
- def a_method_used_for_validation_purposes
- errors.add(:name, :invalid_characters)
- end
+class Person < ActiveRecord::Base
+ def a_method_used_for_validation_purposes
+ errors.add(:name, :invalid_characters)
end
+end
- person = Person.create(name: "!@#")
+person = Person.create(name: "!@#")
- person.errors.details[:name]
- # => [{error: :invalid_characters}]
+person.errors.details[:name]
+# => [{error: :invalid_characters}]
```
-To improve error details to contain not allowed characters set, you can
-pass additional options to `errors.add` method.
+To improve the error details to contain the unallowed characters set for instance,
+you can pass additional keys to `errors.add`.
```ruby
- class Person < ActiveRecord::Base
- def a_method_used_for_validation_purposes
- errors.add(:name, :invalid_characters, not_allowed: "!@#%*()_-+=")
- end
+class Person < ActiveRecord::Base
+ def a_method_used_for_validation_purposes
+ errors.add(:name, :invalid_characters, not_allowed: "!@#%*()_-+=")
end
+end
- person = Person.create(name: "!@#")
+person = Person.create(name: "!@#")
- person.errors.details[:name]
- # => [{error: :invalid_characters, not_allowed: "!@#%*()_-+="}]
+person.errors.details[:name]
+# => [{error: :invalid_characters, not_allowed: "!@#%*()_-+="}]
```
-All built in Rails validators populate details hash with corresponding
-validator types.
+All built in Rails validators populate the details hash with the corresponding
+validator type.
### `errors[:base]`