mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2024-12-22 23:53:15 +01:00
13 lines
375 B
Ruby
13 lines
375 B
Ruby
|
class ParseableDateValidator < ActiveModel::EachValidator
|
||
|
|
||
|
def validate_each(record, attribute, value)
|
||
|
raw_value = record.read_attribute_before_type_cast(attribute)
|
||
|
return nil if raw_value.nil?
|
||
|
Date.parse(raw_value)
|
||
|
nil
|
||
|
rescue ArgumentError => e
|
||
|
record.errors[attribute] << (options[:message] || I18n.t("errors.messages.unparseable_date"))
|
||
|
end
|
||
|
|
||
|
end
|