diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index 7bc3a31..b7c10e5 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -7,9 +7,11 @@ class MatsController < ApplicationController # GET /mats/1.json def show @match = @mat.unfinishedMatches.first - @w1 = @match.wrestler1 - @w2 = @match.wrestler2 - @wrestlers = [@w1,@w2] + if @match + @w1 = @match.wrestler1 + @w2 = @match.wrestler2 + @wrestlers = [@w1,@w2] + end end # GET /mats/new diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index f5afb58..1dd858a 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -148,9 +148,9 @@ class TournamentsController < ApplicationController def check_for_matches if @tournament - if @tournament.matches.empty? - redirect_to "/tournaments/#{@tournament.id}/no_matches" - end + if @tournament.matches.empty? + redirect_to "/tournaments/#{@tournament.id}/no_matches" + end end end end diff --git a/app/models/mat.rb b/app/models/mat.rb index d81fd19..1232dd7 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -4,9 +4,11 @@ class Mat < ActiveRecord::Base def assignNextMatch t_matches = tournament.matches.where(mat_id: nil) - match = t_matches.order(:bout_number).first - match.mat_id = self.id - match.save + if t_matches.size > 0 + match = t_matches.order(:bout_number).first + match.mat_id = self.id + match.save + end end def unfinishedMatches diff --git a/app/models/pooladvance.rb b/app/models/pooladvance.rb index 5f3b7f5..bc10af2 100644 --- a/app/models/pooladvance.rb +++ b/app/models/pooladvance.rb @@ -56,11 +56,11 @@ class Pooladvance def updateNewMatch(match) if @wrestler.nextMatchPositionNumber == @wrestler.nextMatchPositionNumber.ceil match.w2 = @wrestler.id - match.update + match.save end if @wrestler.nextMatchPositionNumber != @wrestler.nextMatchPositionNumber.ceil match.w1 = @wrestler.id - match.update + match.save end end diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index b5dc955..063ad95 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -157,13 +157,13 @@ class Wrestler < ActiveRecord::Base end def seasonWinPercentage - @win = self.season_win.to_f - @loss = self.season_loss.to_f - if @win > 0 and @loss != nil - @matchTotal = @win + @loss - @percentageDec = @win / @matchTotal - @percentage = @percentageDec * 100 - return @percentage.to_i + win = self.season_win.to_f + loss = self.season_loss.to_f + if win > 0 and loss != nil + matchTotal = win + loss + percentageDec = win / matchTotal + percentage = percentageDec * 100 + return percentage.to_i elsif self.season_win == 0 return 0 elsif self.season_win == nil or self.season_loss == nil diff --git a/app/views/mats/show.html.erb b/app/views/mats/show.html.erb index ae2b470..8b4522e 100644 --- a/app/views/mats/show.html.erb +++ b/app/views/mats/show.html.erb @@ -14,6 +14,9 @@

- +<% if @match %> <%= render 'match_edit_form' %> +<% else %> +

No matches assigned to this mat.

+<% end %> diff --git a/app/views/tournaments/up_matches.html.erb b/app/views/tournaments/up_matches.html.erb index 650dbb5..929d3a0 100644 --- a/app/views/tournaments/up_matches.html.erb +++ b/app/views/tournaments/up_matches.html.erb @@ -30,10 +30,10 @@ <% @mats.each.map do |m| %> <%= m.name %> - <%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %> - <%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %> - <%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %> - <%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %> + <% if m.unfinishedMatches.first %><%=m.unfinishedMatches.first.bout_number%>
<%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %><% end %> + <% if m.unfinishedMatches.second %><%=m.unfinishedMatches.second.bout_number%>
<%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %><% end %> + <% if m.unfinishedMatches.third %><%=m.unfinishedMatches.third.bout_number%>
<%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %><% end %> + <% if m.unfinishedMatches.fourth %><%=m.unfinishedMatches.fourth.bout_number%>
<%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %><% end %> <% end %> @@ -54,6 +54,7 @@ + <% if @matches.size > 0 %> <% @matches.each.map do |m| %> Round <%= m.round %> @@ -62,6 +63,7 @@ <%= m.w1_name %> vs. <%= m.w2_name %> <% end %> + <% end %>