Class: Participator

Inherits:
Object
  • Object
show all
Defined in:
app/models/participator.rb

Class Method Summary collapse

Class Method Details

.create!(attendee_hash) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/participator.rb', line 2

def self.create!(attendee_hash)    
  event_id = attendee_hash.delete :event_id
  attendees = []
  attendee_hash.each do |participant_class, participant_ids|
    participant_class = participant_class.to_s.classify.constantize
    if Participant.types.include?(participant_class)
      participant_ids.each do |participant_id|
        next if participant_id.blank? || participant_class.blank?
        attendees << Attendee.create!({
          :event_id => event_id,
          :participant_id => participant_id,
          :participant_type => participant_class
        })
      end
    end
  end
  attendees
end