summaryrefslogtreecommitdiff
path: root/app/controllers/matches_controller.rb
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-03-06 22:17:36 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-03-06 22:17:36 -0500
commit5f2247dd1e701a91fb0359bf7265bdadd5486a60 (patch)
tree8966f53e304731faf26b19230439f831b215d3f1 /app/controllers/matches_controller.rb
parent4a91128f6fe20d95b6692abaa5e6c4dc92418b46 (diff)
parent2bfc17c39f9b8b5ea71d36d2d5f041295f24192f (diff)
Merge branch 'master' of github.com:LukeShu/leaguer
Conflicts: config/routes.rb
Diffstat (limited to 'app/controllers/matches_controller.rb')
-rw-r--r--app/controllers/matches_controller.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 984be3f..23d2700 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -1,10 +1,10 @@
class MatchesController < ApplicationController
+ before_action :set_tournament, only: [:index]
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
@@ -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,19 +54,22 @@ 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
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])
+ @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)