so I am trying to sum month over month the amount that a user has
posted. So for example:
User 1: Jan $3000 Feb $4000 March $1500, etc. I can get this to work
if I sum totals (aggregate of all users) but just not by user.
Here is my code in the controller:
def index
@users = User.find :all, :order => 'name ASC'
@deal_groups = Deal.find(:all).group_by {|t|
t.saledate.at_beginning_of_month}
end
And then the code in the View
<% for user in @users %>
<ul id="monthly-revs">
<strong><li><%=h Time.now.year %></li></strong>
<% user.deal_groups.keys.sort.each do |month| %>
<li><%=h month.strftime('%B') %></li>
<li><%=h number_to_currency(user.deal_groups[month].collect
(&:rev).sum, :precision => 0) %></li>
<% end %>
</ul>
<% end %>
Ultimately, I want to make this a partial but for now am getting the
following error
NoMethodError in Users#index
Showing app/views/users/index.html.erb where line #19 raised:
undefined method `deal_groups' for #<User:0x2200114>
Extracted source (around line #19):
16: <% for user in @users %>
17: <ul id="monthly-revs">
18: <strong><li><%=h Time.now.year %></li></strong>
19: <% user.deal_groups.keys.sort.each do |month| %>
20: <li><%=h month.strftime('%B') %></li>
21: <li><%=h number_to_currency(user.deal_groups[month].collect
(&:rev).sum, :precision => 0) %></li>
22: <% end %>
Thanks in advance
esdevs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---