diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index c499cc0..fc850f2 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -14,11 +14,11 @@ class TournamentsController < ApplicationController end def calculate_team_scores - @tournament.schools.each do |school| - school.calculate_score - end respond_to do |format| - format.html { redirect_to "/tournaments/#{@tournament.id}", notice: 'Team scores are calcuating.' } + if @tournament.calculate_all_team_scores + format.html { redirect_to "/tournaments/#{@tournament.id}", notice: 'Team scores are calcuating.' } + format.json { render action: 'show', status: :created, location: @tournament } + end end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 37edc96..e7243ae 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -40,6 +40,12 @@ class Tournament < ActiveRecord::Base end end + def calculate_all_team_scores + self.schools.each do |school| + school.calculate_score + end + end + def create_pre_defined_weights(weight_classes) weights.destroy_all weight_classes.each do |w|