diff --git a/app/controllers/draws_controller.rb b/app/controllers/draws_controller.rb index 1743c9b..a224a63 100644 --- a/app/controllers/draws_controller.rb +++ b/app/controllers/draws_controller.rb @@ -19,6 +19,15 @@ def update if order.nil? flash[:danger] = 'Constraints could not be satisfied. You can remove some of them and try again.' else + send_draws(order) + flash[:success] = 'Ballots have been drawn and emails sent.' + end + redirect_to @event + end + + private + + def send_draws(order) for (giver, receiver) in order draw = Draw.new(giver: giver, receiver: receiver) @event.draws << draw @@ -27,8 +36,5 @@ def update for draw in @event.draws draw.send_email end - flash[:success] = 'Ballots have been drawn and emails sent.' end - redirect_to @event - end end