Skip to content

Commit 053061d

Browse files
committed
fix attendee distribution to event groups
1 parent f9584e0 commit 053061d

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

app/controllers/admin/groups_controller.rb

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def index
99

1010
def generate
1111

12+
# create a group for each pair of coaches
1213
@coaches = @event.coach_applications.approved.to_a
1314
@coaches.each_slice(2).with_index do |group, index|
1415
event_group = EventGroup.create(event: @event, name: "Group #{index + 1}")
@@ -17,28 +18,15 @@ def generate
1718
end
1819
end
1920

20-
@attendees = @event.applications.application_selected.confirmed
21-
@event.event_groups.each do |event_group|
22-
attendee_group = @attendees.pop()
23-
event_group.applications << attendee_group unless attendee_group.empty?
21+
# add one attendee to each group as long as there are attendees in array
22+
@attendees = @event.applications.application_selected.confirmed.to_a
23+
@attendees.each do |attendee|
24+
@event.event_groups.each do |event_group|
25+
attendee_group = @attendees.pop(1)
26+
event_group.applications << attendee_group unless attendee_group.empty?
27+
end
2428
end
2529

26-
# This needs to be wrapped in a transaction
27-
# @attendees = @event.applications.application_selected.confirmed
28-
# @attendees.each_slice(6).with_index do |group, index|
29-
# event_group = EventGroup.create(event: @event, name: "Group #{index + 1}")
30-
# group.each do |application|
31-
# event_group.applications << application
32-
# end
33-
# end
34-
35-
# @coaches = @event.coach_applications.approved.to_a
36-
# @event.event_groups.each do |event_group|
37-
# # Check if we are assinging the last 2 coaches
38-
# coach_group = @coaches.pop(2)
39-
# event_group.coach_applications << coach_group unless coach_group.empty?
40-
# end
41-
4230
@event_groups = @event.event_groups
4331

4432
redirect_to admin_event_groups_path(@event), notice: "Groups successfully generated"

0 commit comments

Comments
 (0)