Well… I cant get it working
Try to explain it again…
db_table:
week_id, project_id, user_id, hour
ex. =>
33, 1, 1, 10
33, 4, 1, 20
33, 1, 2, 0
34, 1, 2, 15
34, 1, 1, 0
So, user with the id 1 worked 10 hours in week 33 and 20 in the week 33, but other project
I want to show all hours summed up per week per user
row1(user1) => week 33 => 30, week 34 => 0
row2(user2) => week 33 => 0, week 34 => 15
Step one:
I want one row per user, so I group:
@hours = HourUser.all.group_by(&:user_id)
view:
@hours.each do |user, weeks|
gives me each user in one
within this row, each week one cell
<% weeks.group_by(&:week_id).each do |week, hours| %>
<%= hours.map(&:hour).sum %>
Shows the hours but not summed up. Instead I get :
row 1 => …10… and does not stop the row but starts again with … 20…
row 2 => …0 15
How to? Do I also have to group otherwise…?
Thanks for support.