mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Made pool and bout classes. Still need to fix bouts doubling on every
refresh of upcoming matches view
This commit is contained in:
@@ -8,10 +8,8 @@ class StaticPagesController < ApplicationController
|
||||
@tournament = Tournament.find(params[:tournament])
|
||||
end
|
||||
if @tournament
|
||||
@matches = Match.where(tournament_id: @tournament.id)
|
||||
@bouts = @tournament.bouts
|
||||
end
|
||||
@matches = @matches.where(finished: nil)
|
||||
|
||||
end
|
||||
def results
|
||||
if params[:tournament]
|
||||
|
||||
11
app/models/bout.rb
Normal file
11
app/models/bout.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Bout
|
||||
attr_accessor :w1, :w2, :tournament_id
|
||||
def self.all
|
||||
ObjectSpace.each_object(self).to_a
|
||||
end
|
||||
|
||||
def self.count
|
||||
all.count
|
||||
end
|
||||
|
||||
end
|
||||
30
app/models/pool.rb
Normal file
30
app/models/pool.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class Pool
|
||||
def createPool(tournament)
|
||||
@weights = Weight.where(tournament_id: tournament)
|
||||
@weights.each do |weight|
|
||||
roundRobin(weight,tournament)
|
||||
end
|
||||
end
|
||||
|
||||
def createBout(wrestler,tournament)
|
||||
@bout = Bout.new
|
||||
@bout.w1 = wrestler.id
|
||||
@bout.tournament_id = tournament
|
||||
end
|
||||
|
||||
def roundRobin(weight,tournament)
|
||||
@wrestlers = Wrestler.where(weight_id: weight)
|
||||
@wrestlers.each do |wrestler|
|
||||
createBout(wrestler,tournament)
|
||||
end
|
||||
end
|
||||
|
||||
def self.all
|
||||
ObjectSpace.each_object(self).to_a
|
||||
end
|
||||
|
||||
def self.count
|
||||
all.count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,4 +3,11 @@ class Tournament < ActiveRecord::Base
|
||||
has_many :weights, dependent: :destroy
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :mats, dependent: :destroy
|
||||
|
||||
def bouts
|
||||
@pool = Pool.new
|
||||
@pool.createPool(self.id)
|
||||
@bouts = Bout.all
|
||||
return @bouts
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Weight < ActiveRecord::Base
|
||||
belongs_to :tournament
|
||||
has_many :wrestlers, dependent: :destroy
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,45 +1,8 @@
|
||||
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}" %>
|
||||
<br>
|
||||
<br>
|
||||
<h3>Round 1</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 1 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %><% end %>
|
||||
<h3>Upcoming Matches</h3>
|
||||
<% @bouts.each do |m| %>
|
||||
<%= Wrestler.find(m.w1).weight.max %> Lbs <%= Wrestler.find(m.w1).name %> vs. Some Guy
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3>Round 2</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 2 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3>Round 3</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 3 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3>Round 4</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 4 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3>Round 5</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 5 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h3>Round 6</h3>
|
||||
<% @matches.each do |m| %>
|
||||
<% if m.round == 6 %>
|
||||
<%= Wrestler.find(m.r_id).weight.max %> Lbs <%= @weight_class %> LBS <%= Wrestler.find(m.r_id).name %> vs. <%= Wrestler.find(m.g_id).name %> <% if user_signed_in? %><%= link_to "Control Match", "/matches/#{m.id}/edit" %><% end %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user