BUSTED: what a mess. trying to get tournament round generation bits working. ack.
This commit is contained in:
@@ -1,85 +1,62 @@
|
||||
class MashTournamentsController < ApplicationController
|
||||
# GET /mash_tournaments
|
||||
# GET /mash_tournaments.xml
|
||||
def index
|
||||
@mash_tournaments = MashTournament.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @mash_tournaments }
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mash_tournaments/1
|
||||
# GET /mash_tournaments/1.xml
|
||||
def show
|
||||
@mash_tournament = MashTournament.find(params[:id])
|
||||
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
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @mash_tournament }
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mash_tournaments/new
|
||||
# GET /mash_tournaments/new.xml
|
||||
def new
|
||||
return if should_start_mashing?(request.remote_ip)
|
||||
|
||||
@mash_tournament = MashTournament.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @mash_tournament }
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# GET /mash_tournaments/1/edit
|
||||
def edit
|
||||
@mash_tournament = MashTournament.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /mash_tournaments
|
||||
# POST /mash_tournaments.xml
|
||||
def create
|
||||
@mash_tournament = MashTournament.new(params[:mash_tournament])
|
||||
return if should_start_mashing?(request.remote_ip)
|
||||
|
||||
@mash_tournament = MashTournament.new(
|
||||
:requester => Requester.new(:ip => request.remote_ip)
|
||||
)
|
||||
|
||||
respond_to do |format|
|
||||
if @mash_tournament.save
|
||||
flash[:notice] = 'MashTournament was successfully created.'
|
||||
format.html { redirect_to(@mash_tournament) }
|
||||
format.xml { render :xml => @mash_tournament, :status => :created, :location => @mash_tournament }
|
||||
flash[:notice] = "Let's start mashing!"
|
||||
format.html { redirect_to :controller => 'mashes', :action => 'new' }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @mash_tournament.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /mash_tournaments/1
|
||||
# PUT /mash_tournaments/1.xml
|
||||
def update
|
||||
@mash_tournament = MashTournament.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @mash_tournament.update_attributes(params[:mash_tournament])
|
||||
flash[:notice] = 'MashTournament was successfully updated.'
|
||||
format.html { redirect_to(@mash_tournament) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @mash_tournament.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
private
|
||||
def should_start_mashing?(ip)
|
||||
if requester = Requester.find_by_ip(ip)
|
||||
redirect_to :controller => 'mashes', :action => 'new'
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /mash_tournaments/1
|
||||
# DELETE /mash_tournaments/1.xml
|
||||
def destroy
|
||||
@mash_tournament = MashTournament.find(params[:id])
|
||||
@mash_tournament.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(mash_tournaments_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@@ -8,13 +8,16 @@ class MashesController < ApplicationController
|
||||
alias_method :show, :redirect_to_new
|
||||
|
||||
def new
|
||||
@map_a, @map_b = Map.pair
|
||||
return if not already_registered?(request.remote_ip)
|
||||
|
||||
@mash = Mash.new(
|
||||
:map_a => @map_a,
|
||||
:map_b => @map_b,
|
||||
:winner => @map_a
|
||||
)
|
||||
requester = Requester.find_by_ip(request.remote_ip)
|
||||
@mash = requester.current_tournament.next_unplayed_mash
|
||||
|
||||
if not @mash
|
||||
flash[:notice] = "You're done!"
|
||||
redirect_to requester.current_tournament, :action => 'show'
|
||||
return
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
@@ -22,18 +25,18 @@ class MashesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
return if not already_registered?(request.remote_ip)
|
||||
|
||||
mash_params = params[:mash].clone
|
||||
logger.info("Got params: #{params.inspect}")
|
||||
|
||||
requester = Requester.find_or_initialize_by_ip(request.remote_ip)
|
||||
requester.save!
|
||||
requester.reload
|
||||
logger.info("Setting mash.requester_id from #{requester.inspect}")
|
||||
requester = Requester.find_by_ip(request.remote_ip)
|
||||
tournament = requester.mash_tournaments.first
|
||||
mash_params[:tournament_id] = tournament.id
|
||||
|
||||
logger.info("Creating mash with: #{mash_params.inspect}")
|
||||
@mash = Mash.new(mash_params)
|
||||
|
||||
@mash.requester_id = requester.id
|
||||
@winner = Map.find(@mash.winner_id.to_i)
|
||||
@winner.points += 1
|
||||
|
||||
@@ -48,4 +51,13 @@ class MashesController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def already_registered?(ip)
|
||||
if not Requester.find_by_ip(ip)
|
||||
redirect_to :controller => :mash_tournaments, :action => 'new'
|
||||
return false
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user