diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 13:12:40 -0400 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 13:14:19 -0400 |
commit | eacf4fcc2a45142cd865795f35d65341dfe665ad (patch) | |
tree | a66dc8028583c119a040a52d9f69c91e002f03bd /app | |
parent | 751ae75e4b790edfbce2cd2340d5d04b98433405 (diff) |
TournamentsController: better error messages
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/tournaments_controller.rb | 13 |
1 files changed, 11 insertions, 2 deletions
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 |