mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-02 13:24:20 +01:00
13 lines
412 B
Ruby
13 lines
412 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.start_at
|
|
the_start = record.end_at
|
|
return unless the_end.present? && the_end > the_start
|
|
|
|
record.errors[:end_at] << "The end date can't be before the start date. Pick a date after #{the_start}"
|
|
end
|
|
end
|