From bc8be5e217279012cd4dc62e3fc2fe2bd9308b1c Mon Sep 17 00:00:00 2001 From: tkimia Date: Mon, 28 Apr 2014 22:01:00 -0400 Subject: bracket update works --- app/controllers/brackets_controller.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'app/controllers/brackets_controller.rb') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index ac34bfe..b91a2c4 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -11,7 +11,7 @@ class BracketsController < ApplicationController # GET /brackets/1 # GET /brackets/1.json def show - @matches = @tournament.stages.first.matches_ordered + @matches = @tournament.stages.order(:id).first.matches_ordered @numTeams = @tournament.min_teams_per_match @logBase = @numTeams @@ -53,11 +53,11 @@ class BracketsController < ApplicationController # PATCH/PUT /brackets/1.json def update respond_to do |format| - if @bracket.update(bracket_params) - format.html { redirect_to @tournament, notice: 'Bracket was successfully updated.' } + if @bracket.predict_winners(prediction_params) + format.html { redirect_to @tournament, notice: 'Your bracket was made! Check back when this stage finishes to see how you did!' } format.json { head :no_content } else - format.html { render action: 'edit' } + format.html { redirect_to @tournament, notice: 'bracket was not made... :('} format.json { render json: @bracket.errors, status: :unprocessable_entity } end end @@ -86,9 +86,21 @@ class BracketsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def bracket_params + # bracket[user_id] + # bracket[tournament_id] + # bracket[name] + # bracket[matches][#{i}] params.require(:bracket).permit(:user_id, :tournament_id, :name) end + def prediction_params + require 'pp' + puts ""*80 + params.require(:bracket).require(:matches) + end + def is_owner?(bracket) bracket.user == current_user end -- cgit v1.2.3