aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorlulalala <mark@goodlife.tw>2018-04-03 10:52:36 +0800
committerlulalala <mark@goodlife.tw>2019-03-31 22:59:12 +0800
commit2a06f13099b3344e93198728795209bc69501d4a (patch)
tree45fc6da38e37700f68c40549cc9be0bb865f9d69 /activemodel
parentcccbac6df6de18b98e300fdd973758447446dbee (diff)
downloadrails-2a06f13099b3344e93198728795209bc69501d4a.tar.gz
rails-2a06f13099b3344e93198728795209bc69501d4a.tar.bz2
rails-2a06f13099b3344e93198728795209bc69501d4a.zip
Add messages_for
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 805d042cac..bb64bc6264 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -65,6 +65,8 @@ module ActiveModel
extend Forwardable
def_delegators :@errors, :size, :clear, :blank?, :empty?
+ # TODO: forward all enumerable methods after `each` deprecation is removed.
+ def_delegators :@errors, :count
LEGACY_ATTRIBUTES = [:messages, :details].freeze
@@ -199,7 +201,7 @@ module ActiveModel
# person.errors[:name] # => ["cannot be nil"]
# person.errors['name'] # => ["cannot be nil"]
def [](attribute)
- where(attribute.to_sym).map { |error| error.message }
+ messages_for(attribute)
end
# Iterates through each error key, value pair in the error messages hash.
@@ -604,6 +606,10 @@ module ActiveModel
def deprecation_removal_warning(method_name)
ActiveSupport::Deprecation.warn("ActiveModel::Errors##{method_name} is deprecated and will be removed in Rails 6.1")
end
+
+ def deprecation_rename_warning(old_method_name, new_method_name)
+ ActiveSupport::Deprecation.warn("ActiveModel::Errors##{old_method_name} is deprecated. Please call ##{new_method_name} instead.")
+ end
end
# Raised when a validation cannot be corrected by end users and are considered