type cast value before blank check for invalid values

This commit is contained in:
Adam Meehan
2010-08-03 15:04:59 +10:00
parent 34a2d4b558
commit 40e404681e
3 changed files with 18 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ module ValidatesTimeliness
when :datetime
value.to_time.in_time_zone
end
rescue
nil
end
def dummy_time(value)

View File

@@ -35,10 +35,10 @@ module ValidatesTimeliness
raw_value = attribute_raw_value(record, attr_name) || value
return if (@allow_nil && raw_value.nil?) || (@allow_blank && raw_value.blank?)
return record.errors.add(attr_name, :"invalid_#{@type}") if value.blank?
value = type_cast(value)
return record.errors.add(attr_name, :"invalid_#{@type}") if value.blank?
@check_restrictions.each do |restriction|
begin
restriction_value = type_cast(evaluate_option_value(options[restriction], record))