From 598d0314ba5c8972caf1015fb20ff163fbf78fa9 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Thu, 5 Nov 2015 16:36:05 +0000 Subject: [PATCH] Redirect mats#show to no_matches if no matches --- app/controllers/mats_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index 68470d3..7bc3a31 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -1,6 +1,7 @@ class MatsController < ApplicationController before_action :set_mat, only: [:show, :edit, :update, :destroy] before_filter :check_access, only: [:new,:create,:update,:destroy,:edit,:show] + before_filter :check_for_matches, only: [:show] # GET /mats/1 # GET /mats/1.json @@ -91,4 +92,13 @@ class MatsController < ApplicationController redirect_to '/static_pages/not_allowed' end end + + + def check_for_matches + if @mat + if @mat.tournament.matches.empty? + redirect_to "/tournaments/#{@tournament.id}/no_matches" + end + end + end end