Created
July 6, 2016 14:48
-
-
Save jakefolio/2f43e98dfd033a7854423f4da6b44138 to your computer and use it in GitHub Desktop.
Custom validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validation :campaign_date_range, if: :default do | |
# start and end date have been coerced to DateTime | |
required(:starts_at, &:valid_start_date?) | |
required(:ends_at, &:valid_end_date?) | |
def valid_start_date?(value) | |
value > form.ends_at | |
end | |
def valid_end_date?(value) | |
value < form.starts_at | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment