summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/matches_controller.rb17
-rw-r--r--app/views/matches/index.html.erb8
-rw-r--r--app/views/matches/show.html.erb4
3 files changed, 16 insertions, 13 deletions
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)
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index d258638..d635834 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -12,13 +12,13 @@
</thead>
<tbody>
- <% @matches.each do |match| %>
+ <% @tournament.matches.each do |match| %>
<tr>
<td><%= match.tournament %></td>
<td><%= match.name %></td>
- <td><%= link_to 'Show', match %></td>
- <td><%= link_to 'Edit', edit_match_path(match) %></td>
- <td><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ <td><%= link_to 'Show', tournament_match_path(@tournament, match) %></td>
+ <td><%= link_to 'Edit', edit_tournament_match_path(@tournament, match) %></td>
+ <td><%= link_to 'Destroy', tournament_match_path(@tournament, match), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index 9c9cbb4..e95cd07 100644
--- a/app/views/matches/show.html.erb
+++ b/app/views/matches/show.html.erb
@@ -8,5 +8,5 @@
<%= @match.name %>
</p>
-<%= link_to 'Edit', edit_match_path(@match) %> |
-<%= link_to 'Back', matches_path %>
+<%= link_to 'Edit', edit_tournament_match_path(@tournament, @match) %> |
+<%= link_to 'Back', tournament_matches_path %>