From e10bf58ec059ec263c1d1a9dcac608475377868a Mon Sep 17 00:00:00 2001 From: nfoy Date: Thu, 6 Mar 2014 20:39:05 -0500 Subject: matches routed --- app/controllers/matches_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 984be3f..2d8ea5e 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,10 +1,10 @@ class MatchesController < ApplicationController - before_action :set_match, only: [:show, :edit, :update, :destroy] + before_action :set_match #, only: [:show, :edit, :update, :destroy] # GET /matches # GET /matches.json def index - @matches = Match.all + @matches = @tournament.matches end # GET /matches/1 @@ -14,7 +14,7 @@ class MatchesController < ApplicationController # GET /matches/new def new - @match = Match.new + end # GET /matches/1/edit @@ -64,7 +64,7 @@ class MatchesController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_match - @match = Match.find(params[:id]) + @tournament = Tournament.find(params[:tournament_id]) end # Never trust parameters from the scary internet, only allow the white list through. -- cgit v1.2.3-2-g168b From e4fe0192a332a324dd207b370252669c88216488 Mon Sep 17 00:00:00 2001 From: nfoy Date: Thu, 6 Mar 2014 21:15:12 -0500 Subject: matches now belong to tournament --- app/controllers/matches_controller.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 2d8ea5e..23d2700 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,6 +1,6 @@ class MatchesController < ApplicationController - before_action :set_match #, only: [:show, :edit, :update, :destroy] - + before_action :set_tournament, only: [:index] + before_action :set_match, only: [:show, :edit, :update, :destroy] # GET /matches # GET /matches.json def index @@ -24,11 +24,11 @@ class MatchesController < ApplicationController # POST /matches # POST /matches.json def create - @match = Match.new(match_params) + @match = @tournament.matches.build(match_params) respond_to do |format| if @match.save - format.html { redirect_to @match, notice: 'Match was successfully created.' } + format.html { redirect_to tournament_matches_path, notice: 'Match was successfully created.' } format.json { render action: 'show', status: :created, location: @match } else format.html { render action: 'new' } @@ -54,10 +54,10 @@ class MatchesController < ApplicationController # DELETE /matches/1 # DELETE /matches/1.json def destroy + @match.destroy respond_to do |format| - format.html { redirect_to matches_url } - format.json { head :no_content } + format.html { redirect_to tournament_matches_path } end end @@ -65,8 +65,11 @@ class MatchesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_match @tournament = Tournament.find(params[:tournament_id]) + @match = @tournament.matches.find(params[:id]); + end + def set_tournament + @tournament = Tournament.find(params[:tournament_id]) end - # Never trust parameters from the scary internet, only allow the white list through. def match_params params.require(:match).permit(:tournament_id, :name) -- cgit v1.2.3-2-g168b From 3f6f212c1d50a0ae953104524ceffe94095307cf Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Thu, 6 Mar 2014 21:22:15 -0500 Subject: tournament controller to matches redirect --- app/controllers/tournaments_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 6fc3ad6..3f6de26 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,12 +11,16 @@ class TournamentsController < ApplicationController # GET /tournaments/1 # GET /tournaments/1.json def show + unless @tournament.status + redirect_to tournament_matches_page(@tournament) + end end # GET /tournaments/new def new @games = Game.all @tournament = Tournament.new(game: Game.find_by_id(params[:game])) + @tournament.status = 1 end # GET /tournaments/1/edit -- cgit v1.2.3-2-g168b From 2bfc17c39f9b8b5ea71d36d2d5f041295f24192f Mon Sep 17 00:00:00 2001 From: Tomer Kimia Date: Thu, 6 Mar 2014 22:06:32 -0500 Subject: tournaments setup started. NOT FINISHED --- app/controllers/tournaments_controller.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 3f6de26..750a4e7 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -46,8 +46,7 @@ class TournamentsController < ApplicationController # PATCH/PUT /tournaments/1 # PATCH/PUT /tournaments/1.json def update - require 'pp' - pp params + if params[:update_action].nil? check_perms respond_to do |format| @@ -70,8 +69,15 @@ class TournamentsController < ApplicationController format.html { render action: 'permission_denied', status: :forbidden } format.json { render json: "Permission denied", status: :forbidden } end - #when "open" - # TODO + when "open" + respond_to do |format| + if @tournament.setup + format.html { render action: 'show', notice: 'You have joined this tournament.' } + format.json { head :no_content } + end + format.html { render action: 'permission_denied', status: :forbidden } + format.json { render json: "Permission denied", status: :forbidden } + end #when "close" # TODO else -- cgit v1.2.3-2-g168b