1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- class Activity < ApplicationRecord
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- belongs_to :group
- has_many :participants
- has_many :people, through: :participants
- validates :public_name, presence: true
- validates :start, presence: true
- validate :deadline_before_start, unless: "self.deadline.blank?"
- validate :end_after_start, unless: "self.end.blank?"
-
-
- def organizers
- self.participants.includes(:person).where(is_organizer: true)
- end
-
- def is_participant?(person)
- Participant.exists?(
- activity_id: self.id,
- person_id: person.id
- )
- end
-
- def is_organizer?(person)
- Participant.exists?(
- person_id: person.id,
- activity_id: self.id,
- is_organizer: true
- )
- end
- private
-
-
- def deadline_before_start
- if self.deadline > self.start
- errors.add(:deadline, 'must be before start')
- end
- end
-
- def end_after_start
- if self.end < self.start
- errors.add(:end, 'must be after start')
- end
- end
- end
|