7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/validators/date_validator.rb', line 7
def validate_each(record, attribute, value)
@error_hash = options[:error_level].present? ? record.send(options[:error_level]) : record.errors
original_value = value
original_value = record.read_attribute_before_type_cast( attribute ) rescue nil if value.nil?
return if original_value.blank? && options[:allow_blank]
message = options[:time] ? ": #{original_value} is not a valid value. Value must be a date in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format." : ": #{original_value} is not a valid value. Value must be a date in YYYY-MM-DD format."
@error_hash.add(attribute, (options[:message] || message))
else
return unless value.respond_to?(:strftime)
if(options[:after] && (after_message = validate_after_option(record, attribute, value, original_value)) != true)
@error_hash.add(attribute, (options[:after_message] || "#{after_message}."))
end
if(options[:before] && (before_message = validate_before_option(record, attribute, value, original_value)) != true)
@error_hash.add(attribute, (options[:before_message] || "#{before_message}."))
end
end
end
|