<%# Show all players in the tournament %>
<% if @tournament.players.length > 0 %>
Players Here:
<% @tournament.players.each do |p| %>
<%= p.user_name %>
<% end %>
<% else %>
Hmmm.... nobody's here yet! You and your friends should join the tournament.
<% end %>
<%# If user can join, and user hasn't joined already, show the join tournment tag %>
<% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %>
<%= form_tag(tournament_path(@tournament), method: "put") do %>
<%= submit_tag("Join Tournamnet") %>
<% end %>
<% elsif @tournament.players.include?(current_user) %>
<%= form_tag(tournament_path(@tournament), method: "put") do %>
<%= submit_tag("Leave Tournamnet") %>
<% end %>
<% end %>
<%# If user is the host, let them start the tournment %>
<% if @tournament.hosts.include?(current_user) %>
<%= form_tag(tournament_path(@tournament), method: "put") do %>
<% if @tournament.players.count >= @tournament.min_players_per_team * @tournament.min_teams_per_match %>
<%= submit_tag("Start Tournament") %>
<% else %>
<%= submit_tag("Start Tournament", disabled: true) %>
<% end %>
<%= link_to 'Edit', edit_tournament_path(@tournament) %> |
<%= link_to 'Back', tournaments_path %> |
<%= link_to 'Cancel Tournament', @tournament, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>