diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-02-19 14:14:10 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-02-19 14:16:47 +0100 |
commit | 259d33db8cae4f139c4646077f1637a8224dfdb2 (patch) | |
tree | 4c3e10f62ae17e8419578df9cd7ef306dea3dd32 /activemodel/lib | |
parent | ad5834f20f3749cc0f6d512d23f644c64c6bcc2c (diff) | |
parent | fd38838f29ff0f4514b711c65cafe55c6f21ad2a (diff) | |
download | rails-259d33db8cae4f139c4646077f1637a8224dfdb2.tar.gz rails-259d33db8cae4f139c4646077f1637a8224dfdb2.tar.bz2 rails-259d33db8cae4f139c4646077f1637a8224dfdb2.zip |
Merge pull request #18996 from morgoth/deprecate-more-errors-methods
Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methods
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index b1d090b830..166911f0fa 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -347,6 +347,14 @@ module ActiveModel # person.errors.messages # # => {:name=>["can't be empty"]} def add_on_empty(attributes, options = {}) + ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) + ActiveModel::Errors#add_on_empty is deprecated and will be removed in Rails 5.1 + + To achieve the same use: + + errors.add(attribute, :empty, options) if value.nil? || value.empty? + MESSAGE + Array(attributes).each do |attribute| value = @base.send(:read_attribute_for_validation, attribute) is_empty = value.respond_to?(:empty?) ? value.empty? : false @@ -361,6 +369,14 @@ module ActiveModel # person.errors.messages # # => {:name=>["can't be blank"]} def add_on_blank(attributes, options = {}) + ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) + ActiveModel::Errors#add_on_blank is deprecated and will be removed in Rails 5.1 + + To achieve the same use: + + errors.add(attribute, :empty, options) if value.blank? + MESSAGE + Array(attributes).each do |attribute| value = @base.send(:read_attribute_for_validation, attribute) add(attribute, :blank, options) if value.blank? |