Permalink
Browse files

fix state machine, recently played

  • Loading branch information...
1 parent 4cf9537 commit a83fd328cabb15f284b38b013b59350ab5e4cfeb @aserafin aserafin committed Jan 3, 2014
@@ -8,5 +8,5 @@ class Competitor < ActiveRecord::Base
validates :match, :player, :team, presence: true
validates :side, inclusion: { in: %w(home away) }
- validates :match, uniqueness: { scope: [:player_id, :team_id] }
+ #validates :match, uniqueness: { scope: [:player_id, :team_id] }
end
View
@@ -2,13 +2,15 @@ class Match < ActiveRecord::Base
belongs_to :tournament
has_one :score
has_many :competitors
+ has_many :home_competitors, -> { where(side: Competitor::HOME) }, class_name: 'Competitor'
+ has_many :away_competitors, -> { where(side: Competitor::AWAY) }, class_name: 'Competitor'
scope :confirmed, -> { where(state: :confirmed) }
state_machine :state, initial: :pending do
- after_transition on: :finished, do: :send_confirmation_email
- after_transition on: :confirmed, do: :after_confirmation
+ after_transition on: :finish, do: :send_confirmation_email
+ after_transition on: :confirm, do: :after_confirmation
event :finish do
transition pending: :finished
@@ -5,6 +5,14 @@ class Tournament < ActiveRecord::Base
validates :name, presence: true
validates :game, presence: true
+ def self.default
+ Tournament.find(1)
+ end
+
+ def recently_played(limit)
+ self.matches.confirmed.order('created_at desc').limit(limit)
+ end
+
def ranking
::Ranking.new(rating)
end
@@ -0,0 +1,9 @@
+tr
+ td
+ = match_counter + 1
+ td.competitor
+ = match.home_competitors.first.player.name
+ td.score
+ = "#{match.score.home} : #{match.score.away}"
+ td.competitor
+ = match.away_competitors.first.player.name
@@ -0,0 +1,6 @@
+section.recentlyplayed
+ h3 Recently played
+ .table-container
+ table.table
+ tbody
+ = render partial: 'match', collection: Tournament.default.recently_played(10), as: :match
@@ -62,96 +62,7 @@ section.table.standings
.bottom.clearfix
- section.recentlyplayed
- h3 Recently played
- .table-container
- table.table
- tbody
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
- tr
- td 1
- td.competitor Pawel Kowalski
- td.score 7 : 5
- td.competitor Oskar Wroblewski
+ = render partial: 'recently_played'
section.topmatches
h3 Top matches

0 comments on commit a83fd32

Please sign in to comment.