2012-03-09 13:11:54 +00:00
|
|
|
class MashTournamentsController < ApplicationController
|
|
|
|
def index
|
|
|
|
@mash_tournaments = MashTournament.all
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-03-10 13:47:47 +00:00
|
|
|
format.html
|
2012-03-09 13:11:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-03-10 13:47:47 +00:00
|
|
|
begin
|
|
|
|
@mash_tournament = MashTournament.find(params[:id])
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
redirect_to :action => 'new' and return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not @mash_tournament.done?
|
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
end
|
2012-03-09 13:11:54 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2012-03-10 13:47:47 +00:00
|
|
|
format.html
|
2012-03-09 13:11:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2012-03-10 13:47:47 +00:00
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
|
2012-03-09 13:11:54 +00:00
|
|
|
@mash_tournament = MashTournament.new
|
|
|
|
|
|
|
|
respond_to do |format|
|
2012-03-10 13:47:47 +00:00
|
|
|
format.html
|
2012-03-09 13:11:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-03-10 13:47:47 +00:00
|
|
|
return if should_start_mashing?(request.remote_ip)
|
|
|
|
|
|
|
|
@mash_tournament = MashTournament.new(
|
|
|
|
:requester => Requester.new(:ip => request.remote_ip)
|
|
|
|
)
|
2012-03-09 13:11:54 +00:00
|
|
|
respond_to do |format|
|
2012-03-12 04:18:42 +00:00
|
|
|
if @mash_tournament.save && (
|
|
|
|
@mash_tournament.builder.create_rounds_for_contenders(8) == 3
|
|
|
|
) && (
|
|
|
|
@mash_tournament.builder.fill_in_next_round.length == 4
|
|
|
|
)
|
2012-03-10 13:47:47 +00:00
|
|
|
flash[:notice] = "Let's start mashing!"
|
|
|
|
format.html { redirect_to :controller => 'mashes', :action => 'new' }
|
2012-03-09 13:11:54 +00:00
|
|
|
else
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-10 13:47:47 +00:00
|
|
|
private
|
|
|
|
def should_start_mashing?(ip)
|
|
|
|
if requester = Requester.find_by_ip(ip)
|
|
|
|
redirect_to :controller => 'mashes', :action => 'new'
|
|
|
|
return true
|
2012-03-09 13:11:54 +00:00
|
|
|
end
|
|
|
|
|
2012-03-10 13:47:47 +00:00
|
|
|
false
|
2012-03-09 13:11:54 +00:00
|
|
|
end
|
|
|
|
end
|