Merge pull request #33364 from lanzhiheng/fix-document-in-model-validator

Modify the expression's issue for `errors.add` document.

[ci skip]
This commit is contained in:
Ryuta Kamizono 2018-07-16 15:21:25 +09:00 committed by GitHub
commit cd84d87164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 18 deletions

View File

@ -1133,24 +1133,6 @@ person.errors.full_messages
# => ["Name cannot contain the characters !@#%*()_-+="]
```
An equivalent to `errors#add` is to use `<<` to append a message to the `errors.messages` array for an attribute:
```ruby
class Person < ApplicationRecord
def a_method_used_for_validation_purposes
errors.messages[:name] << "cannot contain the characters !@#%*()_-+="
end
end
person = Person.create(name: "!@#")
person.errors[:name]
# => ["cannot contain the characters !@#%*()_-+="]
person.errors.to_a
# => ["Name cannot contain the characters !@#%*()_-+="]
```
### `errors.details`
You can specify a validator type to the returned error details hash using the