application_controller.rb
898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class ApplicationController < HeimdallEngine::ApplicationController
protect_from_forgery with: :exception
def root
leaderboard
check_matches
recent_matches
@results = check_results
end
private
def leaderboard
@leaders = Group.for(current_user.id).inject({}) do |h, group|
h[group.name] = {
pool: group.pool_name,
leaderboard: Bet.for_pool(group.pool_id).board.take(5)
}
h
end
end
def check_matches
@upcoming_matches = Match.active.order(date: :ASC).limit(5)
.where('date > ?', Time.zone.now)
end
def recent_matches
@recent_matches = Match.active.where.not(result: nil)
.order(:date).limit(5)
end
def check_results
return [] unless current_user
current_user.bets.joins(:match).order('matches.date desc')
.where.not(result: nil)
.limit(5)
end
end