application_controller.rb
801 Bytes
class ApplicationController < HeimdallEngine::ApplicationController
protect_from_forgery with: :exception
def root
leaderboard
check_matches
recent_matches
@results = check_results
end
private
def leaderboard
@leaders = Bet.joins(:user).group('users.name').sum(:points)
.sort_by { |k,v| v }.take(5)
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