lecture.rb 418 B

12345678910111213141516171819
  1. class Lecture < ApplicationRecord
  2. belongs_to :course
  3. validates :course_id, presence: true
  4. validates :location, presence: true
  5. validates :starts_at, presence: true
  6. validates :ends_at, presence: true
  7. validate :date_order
  8. default_scope { order(starts_at: :asc) }
  9. private
  10. def date_order
  11. if ends_at < starts_at
  12. errors.add(:ends_on, "should come after starts_on")
  13. end
  14. end
  15. end