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| %>
| Name: <%= @w1.name %> | |||
|---|---|---|---|
| <%= @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 %> |