3 ms·
it'd be nice to get a heads up that this was dependent on using a SQL database.
by hayksaakian 13y ago
it'd be nice to get a heads up that this was dependent on using a SQL database.
- akane 13y agoIt's not dependent on SQL. @pixel.hits is returning an Array, and there is no method group for Array in Ruby. You could try group_by if you really want to group an Array, or use the Mongoid syntax for grouping.
- hayksaakian 13y agoIs this: http://stackoverflow.com/questions/4732393/ordering-and-grouping-in-mongoid http://stackoverflow.com/questions/4732393/ordering-and-grou... What you're referring to?
- akane 13y agoYou may have to use counts from map reduce. I'm not super familiar with the current state of MongoDB. http://mongoid.org/en/mongoid/docs/querying.html#aggregations http://mongoid.org/en/mongoid/docs/querying.html#aggregation... Hopefully someone else can speak to this.
- mnutt 13y agoYou can do the same in just ruby: pie_chart @pixel.hits.group_by{|u| u.referrer }.each_with_object({}) {|(k,v), h| h[k] = v.size }