Last active
August 29, 2015 14:05
-
-
Save zentooo/44b3fc0ce9edfa63d2e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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