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| %>
      <tr>
        <% hours.each do |h|%>
            <td"><%= h.hours %></td>
        <% end %>
      </tr>
  <% end %>
This gives me a row with all week_ids and
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/Aq24zteeCAsJ.
For more options, visit https://groups.google.com/groups/opt_out.
On 11 February 2013 10:11, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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| %> > <tr> > <% hours.each do |h|%> > <td"><%= h.hours %></td> > <% end %> > </tr> > <% end %> > > This gives me a row with all week_ids andYou 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> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/Aq24zteeCAsJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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| %>
      <tr>
        <% hours.each do |h|%>
            <td"><%= h.hours %></td>
        <% end %>
      </tr>
  <% 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...
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/1vNjWob3hrsJ.
For more options, visit https://groups.google.com/groups/opt_out.