From eacf4fcc2a45142cd865795f35d65341dfe665ad Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 13:12:40 -0400 Subject: TournamentsController: better error messages --- app/controllers/tournaments_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'app/controllers/tournaments_controller.rb') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index fdb80aa..e5cfb81 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -50,11 +50,20 @@ class TournamentsController < ApplicationController ok &= @tournament.update(tournament_setting_params) ok &= @tournament.hosts.push(current_user) for i in 1..(params[:num_stages].to_i) do - ok &= @tournament.stages.create(tournament_stage_params(i)) + begin + ok &= @tournament.stages.create(tournament_stage_params(i)) + rescue ActionController::ParameterMissing => e + ok = false + @tournament.errors.add("stages[#{i}]", "Stage #{i} not set") + end end end - rescue + rescue ActiveRecord::RecordNotUnique => e + ok = false + @tournament.errors.add(:name, "must be unique") + rescue => e ok = false + @tournament.errors.add(:exception, "Unknown error: ``#{e.class.name}'' -- #{e.inspect} -- #{e.methods - Object.new.methods}") end respond_to do |format| if ok -- cgit v1.2.3-2-g168b