1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/validators/date_range_validator.rb

13 lines
392 B
Ruby

# frozen_string_literal: true
# Validates that start_at is same or before end_at in the given record
class DateRangeValidator < ActiveModel::Validator
def validate(record)
the_end = record.end_at
the_start = record.start_at
return if the_end.present? && the_end >= the_start
record.errors[:end_at] << I18n.t('errors.messages.end_before_start', START: the_start)
end
end