Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class Booking < ApplicationRecord
  2. belongs_to :developer, counter_cache: true
  3. belongs_to :user
  4.  
  5. validates :start_date, :end_date, presence: true, availability: true
  6. validate :end_date_after_start_date
  7.  
  8. private
  9.  
  10. def end_date_after_start_date
  11. return if end_date.blank? || start_date.blank?
  12.  
  13. if end_date < start_date
  14. errors.add(:end_date, "must be after the start date")
  15. end
  16. end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement