3

I'm having an issue trying to loop through two team results grouping by date. So far my method only produces the first letter of each loop and puts the two results in 2 rows.

My table data is as such:

|matchId|      matchDate    |teamId|goals|
|  101  |2016-05-14 11:40:00|  10  |  3  |
|  101  |2016-05-14 11:40:00|  20  |  2  |

Controller (Would it be possible to group by just week and month?)

@games = Match.all.group_by { |m| m.matchDate }

View

<table class="table table-bordered">
 <th colspan='5'>Match</th>
 <th>Team Name 1</th>
 <th>Team Score 1</th>
 <th></th> 
 <th>Team Name 2</th>
 <th>Team Score 2</th>
 <% @games.each do |date, games| %>
 <tr class="match-date">
  <td colspan='5'><%= date %></td>
 </tr>
  <% games.each do |match| %>
   <tr>
    <td><%= match.teamId[0] %></td>
    <td><%= match.goals[0] %></td>
    <td>VS</td>
    <td><%= match.teamId[1] %></td>
    <td><%= match.goals[1] %></td>
   </tr>
   <% end %>
  <% end %>
 </table>
DollarChills
  • 1,076
  • 1
  • 15
  • 33
  • Possible duplicate of [Loop variable grouping by date](http://stackoverflow.com/questions/39888542/loop-variable-grouping-by-date) – C dot StrifeVII Oct 17 '16 at 22:35

1 Answers1

0

do @games in your view as you are doing @games in controller .. since it is a global var . you can call it in view . i hope this might help

Krishna S
  • 27
  • 3