From f2f1e0b165dfc6cafab01c93efc25d8cd25791d9 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Thu, 30 Sep 2010 19:08:09 +1000 Subject: [PATCH] tiny tweaks --- lib/validates_timeliness/validator.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/validates_timeliness/validator.rb b/lib/validates_timeliness/validator.rb index f9d5ba2..07bf3f4 100644 --- a/lib/validates_timeliness/validator.rb +++ b/lib/validates_timeliness/validator.rb @@ -44,15 +44,13 @@ module ValidatesTimeliness value = parse(raw_value) if value.is_a?(String) || options[:format] value = type_cast_value(value, @type) - if value.blank? - return add_error(record, attr_name, :"invalid_#{@type}") - end + return add_error(record, attr_name, :"invalid_#{@type}") if value.blank? @restrictions_to_check.each do |restriction| begin restriction_value = type_cast_value(evaluate_option_value(options[restriction], record), @type) unless value.send(RESTRICTIONS[restriction], restriction_value) - return add_error(record, attr_name, restriction, format_error_value(restriction_value)) + return add_error(record, attr_name, restriction, restriction_value) end rescue => e unless ValidatesTimeliness.ignore_restriction_errors @@ -63,6 +61,7 @@ module ValidatesTimeliness end def add_error(record, attr_name, message, value=nil) + value = format_error_value(value) if value message_options = { :message => options[:"#{message}_message"], :restriction => value } record.errors.add(attr_name, message, message_options) end