aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-11-25 10:50:00 +0100
committerGitHub <noreply@github.com>2016-11-25 10:50:00 +0100
commitbce2e64e1022dc48577a7b6090fa79adcb559d11 (patch)
tree882e71f1e77f69b2239e71b3727596d6ce2cde0a /activemodel/lib/active_model/errors.rb
parent43e0aee8ccae5bf55e0a63c89c9a322752ea6e05 (diff)
parent9f566aba3278e6e64beb38a88c02a3528760c730 (diff)
downloadrails-bce2e64e1022dc48577a7b6090fa79adcb559d11.tar.gz
rails-bce2e64e1022dc48577a7b6090fa79adcb559d11.tar.bz2
rails-bce2e64e1022dc48577a7b6090fa79adcb559d11.zip
Merge pull request #23675 from kachick/activemodel-errors-indifferent
Adjust to indifferent access around some ActiveModel::Errors methods
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 14adfa081f..5ee9413cff 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -110,6 +110,7 @@ module ActiveModel
# person.errors.include?(:name) # => true
# person.errors.include?(:age) # => false
def include?(attribute)
+ attribute = attribute.to_sym
messages.key?(attribute) && messages[attribute].present?
end
alias :has_key? :include?
@@ -121,8 +122,9 @@ module ActiveModel
# person.errors.delete(:name) # => ["cannot be nil"]
# person.errors[:name] # => []
def delete(key)
- details.delete(key)
- messages.delete(key)
+ attribute = key.to_sym
+ details.delete(attribute)
+ messages.delete(attribute)
end
# When passed a symbol or a name of a method, returns an array of errors
@@ -342,6 +344,7 @@ module ActiveModel
# person.errors.full_messages_for(:name)
# # => ["Name is too short (minimum is 5 characters)", "Name can't be blank"]
def full_messages_for(attribute)
+ attribute = attribute.to_sym
messages[attribute].map { |message| full_message(attribute, message) }
end