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
|
||||
|
||||
Reference in New Issue
Block a user