For example, I would like to sort by game_date, and then if the date is the same, sort it by team? What would be the best way to do this?
@teams = @user.teams
@games = @teams.reduce([]) { |aggregate, team| aggregate + team.games}.sort_by(&:game_date)
The best way would be to have your database do it, but if you want to use Ruby:
The sorting behaviour of
Arrayis to sort by the first member, then the second, then the third, and so on. Since you want the date as your primary key and the team as the second, an array of those two will sort the way you want.