From cfd421daa2b04216e27d666361eb4053020e027d Mon Sep 17 00:00:00 2001 From: James Hill Date: Wed, 5 Aug 2009 11:44:44 -0500 Subject: Allow validations to use values from custom readers [#2936 state:resolved] Signed-off-by: Joshua Peek --- activemodel/lib/active_model/errors.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activemodel/lib/active_model/errors.rb') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index a4cf700231..a47d89ac0e 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -68,7 +68,7 @@ module ActiveModel # Will add an error message to each of the attributes in +attributes+ that is empty. def add_on_empty(attributes, custom_message = nil) [attributes].flatten.each do |attribute| - value = @base.send(attribute) + value = @base.instance_eval { read_attribute_for_validation(attribute) } is_empty = value.respond_to?(:empty?) ? value.empty? : false add(attribute, :empty, :default => custom_message) unless !value.nil? && !is_empty end @@ -77,7 +77,7 @@ module ActiveModel # Will add an error message to each of the attributes in +attributes+ that is blank (using Object#blank?). def add_on_blank(attributes, custom_message = nil) [attributes].flatten.each do |attribute| - value = @base.send(attribute) + value = @base.instance_eval { read_attribute_for_validation(attribute) } add(attribute, :blank, :default => custom_message) if value.blank? end end @@ -146,7 +146,7 @@ module ActiveModel defaults = defaults.compact.flatten << :"messages.#{message}" key = defaults.shift - value = @base.send(attribute) + value = @base.instance_eval { read_attribute_for_validation(attribute) } options = { :default => defaults, :model => @base.class.name.humanize, -- cgit v1.2.3