Ruby on Rails Tuesday, January 4, 2011

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 .

>
> -Rob
>
> Rob Biedenharn
> Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
> rab@GaslightSoftware.com http://GaslightSoftware.com/

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

--
Posted via http://www.ruby-forum.com/.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment