diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/brackets_controller.rb | 17 | ||||
-rw-r--r-- | app/models/tournament.rb | 1 | ||||
-rw-r--r-- | app/views/brackets/index.html.erb | 7 | ||||
-rw-r--r-- | app/views/common/_show_tournament.html.erb | 4 |
4 files changed, 16 insertions, 13 deletions
diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index ebd0c6b..37f1803 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -1,10 +1,11 @@ class BracketsController < ApplicationController - before_action :set_bracket, only: [:show, :edit, :update, :destroy] + before_action :set_tournament, only: [:index, :create] # GET /brackets # GET /brackets.json def index - @brackets = Bracket.all + @tournament = Tournament.find(params[:tournament_id]) + @brackets = @tournament.brackets end # GET /brackets/1 @@ -19,7 +20,7 @@ class BracketsController < ApplicationController # POST /brackets # POST /brackets.json def create - @bracket = Bracket.new(bracket_params) + @bracket = @tournament.brackets.create(user: current_user) respond_to do |format| if @bracket.save @@ -63,8 +64,16 @@ class BracketsController < ApplicationController @bracket = Bracket.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 bracket_params - params.fetch(:bracket, {}).permit(:user_id, :tournament_id, :name) + params.require(:bracket).permit(:user_id, :tournament_id, :name) + end + + def is_owner?(bracket) + bracket.user == current_user end end diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 861be6c..7460a7d 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -1,6 +1,7 @@ class Tournament < ActiveRecord::Base belongs_to :game has_many :stages, class_name: "TournamentStage" + has_many :brackets has_many :settings_raw, class_name: "TournamentSetting" has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments" has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments" diff --git a/app/views/brackets/index.html.erb b/app/views/brackets/index.html.erb index 2195d69..9effe37 100644 --- a/app/views/brackets/index.html.erb +++ b/app/views/brackets/index.html.erb @@ -8,7 +8,6 @@ <th>Name</th> <th></th> <th></th> - <th></th> </tr> </thead> @@ -18,9 +17,8 @@ <td><%= bracket.user %></td> <td><%= bracket.tournament %></td> <td><%= bracket.name %></td> - <td><%= link_to 'Show', bracket %></td> - <td><%= link_to 'Edit', edit_bracket_path(bracket) %></td> - <td><%= link_to 'Destroy', bracket, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= link_to 'Show', tournament_bracket_path(@tournament, bracket) %></td> + <td><%= link_to 'Edit', edit_tournament_bracket_path(@tournament, bracket) %></td> </tr> <% end %> </tbody> @@ -28,4 +26,3 @@ <br> -<%= link_to 'New Bracket', new_bracket_path %> diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index fb31420..b16a37b 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -30,10 +30,6 @@ <p style="margin-top:10px;"> You've signed up for this tournament! </p> <% end %> <%= form_tag(tournament_brackets_path(target), method: "post") do %> - <%= label :user_id, nil, style: "display: none;" %> - <%= text_field_tag :user_id, current_user.id, style: "display: none;" %> - <%= label :tournament_id, nil, style: "display: none;" %> - <%= text_field_tag :tournament_id, target.id, style: "display: none;" %> <%= submit_tag("Make Bracket") %> <% end %> <% end %> |