Fixing contests with closed signups are still joinable

This commit is contained in:
Absurdon 2017-10-30 13:23:12 +01:00
parent 7baac43cbb
commit 60779b8c05
2 changed files with 7 additions and 5 deletions

View file

@ -26,11 +26,11 @@ class ContestersController < ApplicationController
@contester.score = @contester.contest.contesters.active.count + 1
end
if @contester.save!
if @contester.save
flash[:notice] = t(:contests_join)
redirect_to contest_path(@contester.contest_id)
else
flash[:error] = @contester.errors.full_messages.to_s #t(:errors) + @contester.errors.full_messages.to_s
flash[:error] = @contester.errors.full_messages[0]
redirect_to_back
end
end

View file

@ -43,7 +43,7 @@ class Contester < ActiveRecord::Base
validates_inclusion_of [:score, :win, :loss, :draw, :extra], :in => 0..9999, :allow_nil => true
validates_uniqueness_of :team_id, :scope => :contest_id, :message => "You can't join same contest twice."
#validate_on_create:validate_member_participation
#validate_on_create:validate_contest
validate :validate_contest, :on => :create
#validate_on_create:validate_playernumber
before_create :init_variables
@ -87,8 +87,10 @@ class Contester < ActiveRecord::Base
end
def validate_contest
if contest.end.past? or contest.status == Contest::STATUS_CLOSED
errors.add :contest, I18n.t(:contests_closed)
if contest.end.past?
self.errors.add :base, "Cannot join contest! It is already over!"
elsif contest.status != Contest::STATUS_OPEN
self.errors.add :base, "Cannot join contest! Signups are closed!"
end
end