Skip to content

Instantly share code, notes, and snippets.

@zentooo
Last active August 29, 2015 14:05
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 zentooo/44b3fc0ce9edfa63d2e4 to your computer and use it in GitHub Desktop.
Save zentooo/44b3fc0ce9edfa63d2e4 to your computer and use it in GitHub Desktop.
class Sample2 < ActiveRecord::Base
validate :check_start_date_and_end_date
def check_start_date_and_end_date
if start_date.nil?
errors.add(:start_date, "start date should not be nil")
end
if end_date.nil?
errors.add(:end_date, "end date should not be nil")
end
return unless errors.empty?
if start_date > end_date
errors.add(:start_date, "start date should be past of end date")
errors.add(:end_date, "start date should be past of end date")
end
if end_date - start_date < 1.hour
errors.add(:start_date, "start date and end date should have one hour gap")
errors.add(:end_date, "start date and end date should have one hour gap")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment