【发布时间】:2017-02-14 18:12:52
【问题描述】:
我有一些体育赛事的结果,我想在表格中循环查看并根据日期分组。例如;
|Sat, 20|
|Game 1 Results|
|Game 2 Results|
|Sun, 21|
|Game 3 Results|
|Sat, 27|
|Game 4 Results|
我的控制器
@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
目前我正在做一个基本循环,它正在显示。
|Sat, 20|
|Game 1 Results|
|Sat, 20|
|Game 2 Results|
|Sun, 21|
|Game 3 Results|
|Sat, 27|
|Game 4 Results|
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4