I have some sporting results that i'd like to loop through and group under dates in a table. For example;
|Sat, 20|
|Game 1 Results|
|Game 2 Results|
|Sun, 21|
|Game 3 Results|
|Sat, 27|
|Game 4 Results|
My Controller
@matches = Match.group([:matchId, 'DATE(matchDate)']).inject([]) do |results, matches|
team_names = Match.where(matchId: matches.matchId)
results << [matches.id, matches.matchDate, team_names.first.team.name, team_names.last.team.name, team_names.first.points, team_names.last.points]
end
At the moment i'm doing a basic loop, which is showing.
|Sat, 20|
|Game 1 Results|
|Sat, 20|
|Game 2 Results|
|Sun, 21|
|Game 3 Results|
|Sat, 27|
|Game 4 Results|