course.rb 524 B

12345678910111213141516171819202122
  1. class Course < ApplicationRecord
  2. belongs_to :school
  3. validates :school_id, presence: true
  4. validates :name, presence: true, length: { maximum: 255 }
  5. validates :starts_on, presence: true
  6. validates :ends_on, presence: true
  7. validate :date_order
  8. has_many :course_participations, dependent: :destroy
  9. has_many :users, through: :course_participations
  10. has_many :lectures
  11. private
  12. def date_order
  13. if ends_on < starts_on
  14. errors.add(:ends_on, "should come after starts_on")
  15. end
  16. end
  17. end