Permalink
Browse files

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.
  • Loading branch information...
1 parent d4c30a0 commit 1e00ab35dad61d681c0d5a16b4babeb0eaae7036 @rafaelfranca committed Dec 26, 2012
Showing with 3 additions and 9 deletions.
  1. +1 −7 activemodel/lib/active_model/errors.rb
  2. +2 −2 activemodel/lib/active_model/validations/presence.rb
@@ -322,15 +322,9 @@ def add_on_empty(attributes, options = {})
# 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
@@ -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

0 comments on commit 1e00ab3

Please sign in to comment.