diff options
author | tkimia <tkimia@purdue.edu> | 2014-04-26 19:39:57 -0400 |
---|---|---|
committer | tkimia <tkimia@purdue.edu> | 2014-04-26 19:39:57 -0400 |
commit | 93e291c8e5002fdea906bb8c96cd528fa8b75935 (patch) | |
tree | 0b000e5c51f8928ba37859bfc0bc7086cd3c272a | |
parent | 96dd3fbe302eec54b34678e098d3b59710b09b5f (diff) |
brackets just get created
-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 | ||||
-rw-r--r-- | db/seeds.rb | 2 |
5 files changed, 17 insertions, 14 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 %> diff --git a/db/seeds.rb b/db/seeds.rb index 87bf540..0917afc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,7 +7,7 @@ # Mayor.create(name: 'Emanuel', city: cities.first) # p = User.permission_bits -Server.create(default_user_permissions: p[:join_tournament] | p[:create_pm]) +Server.create(default_user_permissions: p[:join_tournament] | p[:create_pm] | p[:create_bracket] | p[:edit_bracket]) Game.create(name: "League of Legends",min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true, sampling_method: "Manual,Double Blind,RiotAPI") Game.create(name: "Chess", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true, sampling_method: "Manual,Double Blind") |