mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add documentation about method to describe how it works [ci skip]
This commit is contained in:
parent
e22404a8b2
commit
e38ced376f
1 changed files with 9 additions and 0 deletions
|
@ -160,6 +160,15 @@ module ActiveModel
|
|||
#
|
||||
# person.errors[:name] # => ["cannot be nil"]
|
||||
# person.errors['name'] # => ["cannot be nil"]
|
||||
#
|
||||
# Note that, if you try to get errors of an attribute which has
|
||||
# no errors associated with it, this method will instantiate
|
||||
# an empty error list for it and +keys+ will return an array
|
||||
# of error keys which includes this attribute.
|
||||
#
|
||||
# person.errors.keys # => []
|
||||
# person.errors[:name] # => []
|
||||
# person.errors.keys # => [:name]
|
||||
def [](attribute)
|
||||
messages[attribute.to_sym]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue