app/controllers/tournaments_controller.rb
class TournamentsController < ApplicationController
# GET /tournaments
# GET /tournaments.json
def index
@tournaments = Tournament.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tournaments }
end
end
# GET /tournaments/1
# GET /tournaments/1.json
def show
@tournament = Tournament.find(params[:id])
@players = @tournament.tournament_players_sorted_by_prestige
@matches = @tournament.matches.reverse
respond_to do |format|
format.html # show.html.erb
format.json { render json: @tournament }
end
end
# GET /tournaments/new
# GET /tournaments/new.json
def new
@tournament = Tournament.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @tournament }
end
end
# GET /tournaments/1/edit
def edit
@tournament = Tournament.find(params[:id])
end
# POST /tournaments
# POST /tournaments.json
def create
@tournament = Tournament.new(params[:tournament])
respond_to do |format|
if @tournament.save
format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' }
format.json { render json: @tournament, status: :created, location: @tournament }
else
format.html { render action: "new" }
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
end
# PUT /tournaments/1
# PUT /tournaments/1.json
def update
@tournament = Tournament.find(params[:id])
respond_to do |format|
if @tournament.update_attributes(params[:tournament])
format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tournaments/1
# DELETE /tournaments/1.json
def destroy
@tournament = Tournament.find(params[:id])
@tournament.destroy
respond_to do |format|
format.html { redirect_to tournaments_url }
format.json { head :no_content }
end
end
def start_tournament
@tournament = Tournament.find(params[:tournament_id])
@tournament.start_tournament
respond_to do |format|
format.html { redirect_to @tournament, notice: 'Tournament has started!' }
end
end
def next_round
@tournament = Tournament.find(params[:tournament_id])
@tournament.next_round
respond_to do |format|
format.html { redirect_to @tournament, notice: 'Next Round is Ready' }
end
end
end