mirror of https://github.com/rails/rails
Add documentation about method to describe how it works [ci skip]
This commit is contained in:
parent
e22404a8b2
commit
e38ced376f
|
@ -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 New Issue