Werner
1
Again I need some help with grouping&sum
Attributes:
user_id, week_id, project_id, hours
1 61 1 20
1 62 1 5
1 62 2 0
1 61 2 15
1 63
What I need is a table row per user
61 62 63…
35 5
View:
<% @hour_users.group_by(&:user_id).each do |user, hours| %>
<% hours.each do |h|%>
<td"><%= h.hours %>
<% end %>
<% end %>
This gives me a row with all week_ids and
Werner
2
On 11 February 2013 10:11, Werner [email protected]
wrote:
<% end %>
</tr>
<% end %>
This gives me a row with all week_ids and
You need to tell us the classes and relationships, but if you want a
row per user why are you not starting
@users.each do |user|
Colin
Werner
3
Sorry the posting was send by mistake…
this is the correct question:
Again I need some help with grouping&sum
Attributes:
user_id, week_id, project_id, hours
1 61 1 20
1 62 1 5
1 62 2 0
1 61 2 15
1 63 1 0
What I need is a table row per user like that:
61 62 63(week_id)
35 5 0… Sum of hours per user of all projects, per week_id
View:
<% @hour_users.group_by(&:user_id).each do |user, hours| %>
<% hours.each do |h|%>
<td"><%= h.hours %>
<% end %>
<% end %>
This gives me a row with all week_id’s and the hours per user but not
summed up by project_id.
How do I have to group that ?
Thanks…