mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
13 lines
413 B
Ruby
13 lines
413 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
|