aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-02-04 11:06:28 -0700
committerSean Griffin <sean@seantheprogrammer.com>2016-02-04 11:06:28 -0700
commitea59b68d7570f596671679fbe91b382bcd130594 (patch)
tree0960258bd8063b6c89ca0debcca06e98deaf3b97 /activemodel/lib/active_model/errors.rb
parent2e46ccbecbf83ba5af781c6e626ace7d97b44a13 (diff)
parente38ced376fc4f67036d44bd905fb03dcc12782f7 (diff)
downloadrails-ea59b68d7570f596671679fbe91b382bcd130594.tar.gz
rails-ea59b68d7570f596671679fbe91b382bcd130594.tar.bz2
rails-ea59b68d7570f596671679fbe91b382bcd130594.zip
Merge pull request #23481 from meinac/activemodel_errors_doc_for_behaviour
Add documentation about `ActiveModel::Errors#[]` method to describe how it works [ci skip]
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index ef6141a51d..ea69e7549e 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -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