diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-26 18:20:48 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-26 18:55:47 -0300 |
commit | 78fd14c8de9577f92ee78ba399ca716589465465 (patch) | |
tree | ef36965587b9f6df7a88a99e7b06dc5d0fd3c421 /activemodel/lib | |
parent | d4c30a0226386f291bd8b1959fed12b3aca19164 (diff) | |
download | rails-78fd14c8de9577f92ee78ba399ca716589465465.tar.gz rails-78fd14c8de9577f92ee78ba399ca716589465465.tar.bz2 rails-78fd14c8de9577f92ee78ba399ca716589465465.zip |
Revert the change at ActiveModel::Errors#add_on_blank and fix in the
right place.
The EachValidator#validate already handle :allow_blank and :allow_nil,
correctly.
Closes #8622.
Fix #8621.
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 8 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/presence.rb | 4 |
2 files changed, 3 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 92c2512aa4..963e52bff3 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -322,15 +322,9 @@ module ActiveModel # person.errors.messages # # => {:name=>["can't be blank"]} def add_on_blank(attributes, options = {}) - return if options[:allow_blank] - Array(attributes).each do |attribute| value = @base.send(:read_attribute_for_validation, attribute) - if value.nil? - add(attribute, :blank, options) unless options[:allow_nil] - elsif value.blank? - add(attribute, :blank, options) - end + add(attribute, :blank, options) if value.blank? end end diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb index ae84c376b9..ab8c8359fc 100644 --- a/activemodel/lib/active_model/validations/presence.rb +++ b/activemodel/lib/active_model/validations/presence.rb @@ -3,8 +3,8 @@ module ActiveModel module Validations class PresenceValidator < EachValidator # :nodoc: - def validate(record) - record.errors.add_on_blank(attributes, options) + def validate_each(record, attr_name, value) + record.errors.add(attr_name, :blank, options) if value.blank? end end |