Skip to content

Instantly share code, notes, and snippets.

@jakefolio
Created July 6, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakefolio/2f43e98dfd033a7854423f4da6b44138 to your computer and use it in GitHub Desktop.
Save jakefolio/2f43e98dfd033a7854423f4da6b44138 to your computer and use it in GitHub Desktop.
Custom validation
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