aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-03-28 13:44:35 -0400
committerGitHub <noreply@github.com>2017-03-28 13:44:35 -0400
commit29d6e9cdc4d8528b6676843509347fc8fead935b (patch)
tree1f49483d8742b192acd67bc3b1facf39566ef85e /activemodel/lib
parent5307f8d49cc4d8a5fb331335be4f3b51d83c217d (diff)
parent01269aede398f63e5ef68ebe0f0dafbc472c686e (diff)
downloadrails-29d6e9cdc4d8528b6676843509347fc8fead935b.tar.gz
rails-29d6e9cdc4d8528b6676843509347fc8fead935b.tar.bz2
rails-29d6e9cdc4d8528b6676843509347fc8fead935b.zip
Merge pull request #28584 from bogdanvlviv/errors-keys-values-fix
Fix ActiveModel::Errors #keys, #values
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb17
1 files changed, 6 insertions, 11 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 9df4ca51fe..5d3472802b 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -132,15 +132,6 @@ 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
@@ -181,7 +172,9 @@ module ActiveModel
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
# person.errors.values # => [["cannot be nil", "must be specified"]]
def values
- messages.values
+ messages.reject do |key, value|
+ value.empty?
+ end.values
end
# Returns all message keys.
@@ -189,7 +182,9 @@ module ActiveModel
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
# person.errors.keys # => [:name]
def keys
- messages.keys
+ messages.reject do |key, value|
+ value.empty?
+ end.keys
end
# Returns +true+ if no errors are found, +false+ otherwise.