From 5b497e9cf9c1975930c6e1ee84ed044cd0956ca8 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 5 Nov 2015 09:05:44 -0500 Subject: [PATCH] Added spot to control a match --- app/controllers/mats_controller.rb | 6 +++- app/views/mats/_match_edit_form.html.erb | 37 ++++++++++++++++++++++++ app/views/mats/show.html.erb | 14 ++++++--- app/views/tournaments/show.html.erb | 3 +- 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 app/views/mats/_match_edit_form.html.erb diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index b1880f6..68470d3 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -1,10 +1,14 @@ class MatsController < ApplicationController before_action :set_mat, only: [:show, :edit, :update, :destroy] - before_filter :check_access, only: [:new,:create,:update,:destroy,:edit] + before_filter :check_access, only: [:new,:create,:update,:destroy,:edit,:show] # GET /mats/1 # GET /mats/1.json def show + @match = @mat.unfinishedMatches.first + @w1 = @match.wrestler1 + @w2 = @match.wrestler2 + @wrestlers = [@w1,@w2] end # GET /mats/new diff --git a/app/views/mats/_match_edit_form.html.erb b/app/views/mats/_match_edit_form.html.erb new file mode 100644 index 0000000..014f5cc --- /dev/null +++ b/app/views/mats/_match_edit_form.html.erb @@ -0,0 +1,37 @@ +<%= form_for(@match) do |f| %> + <% if @match.errors.any? %> +
+

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

+ + +
+ <% end %> + +

Bout <%= @match.bout_number %> <%= @w1.name %> VS. <%= @w2.name %>

+
+
+ <%= f.label "Win Type" %>
+ <%= f.select(:win_type, Match::WIN_TYPES) %> +
+
+ <%= f.label "Winner" %> Please put in the id of the winner
+ <%= f.collection_select :winner_id, @wrestlers, :id, :name %> +
+
+ <%= f.label "Score" %> Also put pin time here if applicable. If default or forfeit, leave blank
+ <%= f.text_field :score %> +
+ + <%= f.hidden_field :finished, :value => 1 %> + <%= f.hidden_field :round, :value => @match.round %> + +
+ +
+ <%= f.submit data: { confirm: "Did you confirm the winner before submitting? If not, please hit cancel."}, :class=>"btn btn-success" %> +
+<% end %> diff --git a/app/views/mats/show.html.erb b/app/views/mats/show.html.erb index 9fa0b69..ae2b470 100644 --- a/app/views/mats/show.html.erb +++ b/app/views/mats/show.html.erb @@ -1,13 +1,19 @@

<%= notice %>

+<%= link_to "Back to #{@mat.tournament.name}", "/tournaments/#{@mat.tournament.id}", :class=>"btn btn-default" %> +
+

- Name: - <%= @mat.name %> + Mat <%= @mat.name %>

Tournament: - <%= @mat.tournament_id %> + <%= @mat.tournament.name %>

-<%= link_to 'Edit', edit_mat_path(@mat) %> | +
+
+ +<%= render 'match_edit_form' %> + diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index e44e5e4..d4d02d5 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -128,7 +128,8 @@ <%= mat.name %> <% if tournament_permissions(@tournament) %> - <%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %> + <%= link_to 'Show', mat, :class=>"btn btn-default" %> + <%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %> <% end %>