diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 934add7..7e817fb 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -16,6 +16,7 @@ class MatchesController < ApplicationController end if @match @wrestlers = @match.weight.wrestlers + @tournament = @match.tournament end session[:return_path] = "/tournaments/#{@match.tournament.id}/matches" end @@ -24,10 +25,36 @@ class MatchesController < ApplicationController if params[:match] @match = Match.where(:id => params[:match]).includes(:wrestlers).first end + @wrestlers = [] if @match - @w1 = @match.wrestler1 - @w2 = @match.wrestler2 - @wrestlers = [@w1,@w2] + if @match.w1 + @wrestler1_name = @match.wrestler1.name + @wrestler1_school_name = @match.wrestler1.school.name + if @match.wrestler1.last_match + @wrestler1_last_match = time_ago_in_words(@match.wrestler1.last_match.updated_at) + else + @wrestler1_last_match = "N/A" + end + @wrestlers.push(@match.wrestler1) + else + @wrestler1_name = "Not assigned" + @wrestler1_school_name = "N/A" + @wrestler1_last_match = "N/A" + end + if @match.w2 + @wrestler2_name = @match.wrestler2.name + @wrestler2_school_name = @match.wrestler2.school.name + if @match.wrestler2.last_match + @wrestler2_last_match = time_ago_in_words(@match.wrestler2.last_match.updated_at) + else + @wrestler1_last_match = "N/A" + end + @wrestlers.push(@match.wrestler2) + else + @wrestler2_name = "Not assigned" + @wrestler2_school_name = "N/A" + @wrestler2_last_match = "N/A" + end @tournament = @match.tournament end session[:return_path] = "/tournaments/#{@tournament.id}/matches" diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index 9493c0f..8cdc83b 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -30,6 +30,7 @@ class WrestlersController < ApplicationController # GET /wrestlers/1/edit def edit + @tournament = @wrestler.tournament @weight = @wrestler.weight @weights = @school.tournament.weights.sort_by{|w| w.max} @school = @wrestler.school diff --git a/app/models/match.rb b/app/models/match.rb index 0a3a98a..b5f5d2c 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -28,6 +28,9 @@ class Match < ActiveRecord::Base def score_validation if finished == 1 + if ! winner_id + errors.add(:winner_id, "cannot be blank") + end if win_type == "Pin" and ! score.match(/^[0-5]?[0-9]:[0-5][0-9]/) errors.add(:score, "needs to be in time format MM:SS when win type is Pin example: 1:23 or 10:03") end diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index e7a94d1..f51a643 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -2,12 +2,12 @@ <%= form_for(@match) do |f| %>
<%= f.label "Wrestler 1" %>
- <%= f.collection_select :w1, @wrestlers, :id, :name %> + <%= f.collection_select :w1, @wrestlers, :id, :name, include_blank: true %>
vs
<%= f.label "Wrestler 2" %>
- <%= f.collection_select :w2, @wrestlers, :id, :name %> + <%= f.collection_select :w2, @wrestlers, :id, :name, include_blank: true %>
<%= f.submit onclick: "return confirm('Is the name of the winner ' + document.getElementById('match_winner_id').options[document.getElementById('match_winner_id').selectedIndex].text + '?')", :class=>"btn btn-success" %> diff --git a/app/views/matches/_matchstats.html.erb b/app/views/matches/_matchstats.html.erb index 30d947b..d2568b7 100644 --- a/app/views/matches/_matchstats.html.erb +++ b/app/views/matches/_matchstats.html.erb @@ -15,34 +15,34 @@ - - + +
School: <%= @wrestler2_school_name %> +
Last Match: <%= @wrestler2_last_match %> - - + + - - - - - - @@ -83,7 +83,7 @@
<%= f.label "Winner" %> Please choose the winner
- <%= f.collection_select :winner_id, @wrestlers, :id, :name %> + <%= f.collection_select :winner_id, @wrestlers, :id, :name, include_blank: true %>

diff --git a/app/views/matches/stat.html.erb b/app/views/matches/stat.html.erb index 126efae..f1f802e 100644 --- a/app/views/matches/stat.html.erb +++ b/app/views/matches/stat.html.erb @@ -1,2 +1,2 @@ -

<%= @w1.name %> VS. <%= @w2.name %>

+

<%= @wrestler1_name %> VS. <%= @wrestler2_name %>

<%= render 'matchstats' %> \ No newline at end of file diff --git a/app/views/tournaments/matches.html.erb b/app/views/tournaments/matches.html.erb index 1766120..9bbcc3c 100644 --- a/app/views/tournaments/matches.html.erb +++ b/app/views/tournaments/matches.html.erb @@ -28,9 +28,7 @@
<% end %>
Name: <%= @w1.name %> Name: <%= @wrestler1_name %> -
School: <%= @w1.school.name %> -
Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w1.last_match.updated_at) else "N/A" end%>
Name: <%= @w2.name %> Name: <%= @wrestler2_name %> -
School: <%= @w2.school.name %> -
Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) else "N/A" end%>
<%= @w1.name %> Stats:
<%= f.text_area :w1_stat, cols: "30", rows: "10" %>
<%= @w2.name %> Stats:
<%= f.text_area :w2_stat, cols: "30", rows: "10" %>
<%= @wrestler1_name %> Stats:
<%= f.text_area :w1_stat, cols: "30", rows: "10" %>
<%= @wrestler2_name %> Stats:
<%= f.text_area :w2_stat, cols: "30", rows: "10" %>
<%= @w1.name %> Scoring
+
<%= @wrestler1_name %> Scoring
<%= @w2.name %> Scoring
+
<%= @wrestler2_name %> Scoring
@@ -51,19 +51,19 @@
<%= @w1.name %> Choice
+
<%= @wrestler1_name %> Choice
<%= @w2.name %> Choice
+
<%= @wrestler2_name %> Choice
<%= @w1.name %> Warnings
+
<%= @wrestler1_name %> Warnings
<%= @w2.name %> Warnings
+
<%= @wrestler2_name %> Warnings
<%= match.finished %> <%= link_to 'Show', match, :class=>"btn btn-default btn-sm" %> <%= link_to 'Edit Wrestlers', edit_match_path(match), :class=>"btn btn-primary btn-sm" %> - <% if match.w1 and match.w2 %> <%= link_to 'Stat Match', "/matches/#{match.id}/stat", :class=>"btn btn-primary btn-sm" %> - <% end %>