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 ++++---- app/models/match.rb | 1 + app/views/matches/_form.html.erb | 15 ++------------- app/views/matches/index.html.erb | 2 +- app/views/matches/new.html.erb | 2 +- config/routes.rb | 10 ++++------ 6 files changed, 13 insertions(+), 25 deletions(-) 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. diff --git a/app/models/match.rb b/app/models/match.rb index 533435a..8acebf7 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,3 +1,4 @@ class Match < ActiveRecord::Base belongs_to :tournament + end diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index c5f1ba8..015aed0 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -1,16 +1,5 @@ -<%= form_for(@match) do |f| %> - <% if @match.errors.any? %> -
-

<%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

- - -
- <% end %> - +<%= form_for([@tournament, @tournament.matches.build]) do |f| %> +
<%= f.label :tournament_id %>
<%= f.text_field :tournament_id %> diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 0742770..d258638 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -26,4 +26,4 @@
-<%= link_to 'New Match', new_match_path %> +<%= link_to 'New Match', new_tournament_match_path %> diff --git a/app/views/matches/new.html.erb b/app/views/matches/new.html.erb index bd4c78c..9ac669f 100644 --- a/app/views/matches/new.html.erb +++ b/app/views/matches/new.html.erb @@ -2,4 +2,4 @@ <%= render 'form' %> -<%= link_to 'Back', matches_path %> + diff --git a/config/routes.rb b/config/routes.rb index 2409eb2..72445c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,12 +13,10 @@ Leaguer::Application.routes.draw do resources :teams - resources :matches - - resources :tournaments - - #set 'selected' to: 'tournaments#selected' via: 'get' - + resources :tournaments do + resources :matches + end + resources :servers root to: 'static#homepage' -- cgit v1.1-4-g5e80