On Jan 4, 2011, at 10:57 AM, Marnen Laibow-Koser wrote:
Rob Biedenharn wrote in post #972151:
[...]
You might also just get the counts from the database directly:
results = User.find(:all,
:select => 'DATE(created_at) as create_date, COUNT(*) as
user_count',
:conditions => { :created_at => start_date..end_date },
:group => 'DATE(created_at)').
map{|u| [Date.parse(u.create_date), u.user_count.to_i]}
data = date_range.map {|d| [d.strftime("%d %b"),
(results.assoc(d) || [nil,0])[1]] }
Or better yet, use User.count instead of .find .
But the OP wanted counts by day, not a single total.
-Rob
-Rob
Rob Biedenharn
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
--
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.