Created
August 19, 2012 21:04
-
-
Save RobertBrewitz/3397698 to your computer and use it in GitHub Desktop.
Date validation for booking system
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
... | |
field :started_at, type: Date | |
validates_presence_of :started_at, message: 'you have to provide a start-date' | |
validates_date :started_at, on_or_after: :today, on: :create | |
validates_date :started_at, is_at: lambda { |_self| _self.started_at_was }, on: :update, if: lambda { |_self| _self.started_at_was.to_date < Time.now.to_date } | |
validates_date :started_at, on_or_after: :today, on: :update, if: lambda { |_self| _self.started_at_was.to_date >= Time.now.to_date } | |
field :ended_at, type: Date | |
validates_presence_of :ended_at, message: 'you have to provide an end-date' | |
validates_date :ended_at, on_or_after: lambda { |_self| _self.started_at } | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment