From 9d8e0850bc7c8bf1645ddfed3f9ede15aec05c94 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Tue, 26 May 2015 18:27:55 +0000 Subject: [PATCH] Refactored generating matches --- app/controllers/static_pages_controller.rb | 18 +++++++++--------- app/models/tournament.rb | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 9c63f02..2b3d3da 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -87,15 +87,15 @@ class StaticPagesController < ApplicationController end def generate_matches - if user_signed_in? - else + if !user_signed_in? redirect_to root_path - end - if params[:tournament] - @tournament = Tournament.find(params[:tournament]) - end - if @tournament - @tournament.generateMatchups - end + elsif user_signed_in? + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + end + if @tournament + @tournament.generateMatchups + end + end end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index b41c740..dd8c8b9 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -13,7 +13,7 @@ class Tournament < ActiveRecord::Base @matches = Match.where(tournament_id: self.id) end - def createCustomWeights(value) + def createCustomWeights(value) self.weights.destroy_all if value == 'hs' @weights = [106,113,120,132,138,145,152,160,170,182,195,220,285] @@ -30,7 +30,6 @@ class Tournament < ActiveRecord::Base if matches.nil? return nil else - generateMatchups matches end end