Rails 3 custom validation question: Validating Dates
Have two fields "start" and "end", both are dates, I want to write a custom validator for a scheduling model. The validator checks to see if start is before end, then does a query to see if tho开发者_运维问答se dates have been selected before. While I know how to do it for a single field, when two fields are involved I've gotten lost.
Any help would be great.
Checkout this validates timeliness
Which gives tons of useful validators like
validates_date :date_of_birth :before => lambda { 18.years.ago },
:before_message => "must be at least 18 years old"
validates_time :breakfast_time, :on_or_after => '6:00am',
:on_or_after_message => 'must be after opening time',
:before => :second_breakfast_time,
:allow_nil => true
validates_datetime :appointment_date, :before => lambda { 1.week.from_now }
精彩评论