4 ms·
Hmm. I'm getting a undefined method `group' for #<Array:0x3a32f0c> error with <%= pie_chart @pixel.hits.group("referrer").count %> using mongoid 3,
by hayksaakian 13y ago
Hmm. I'm getting a
undefined method `group' for #<Array:0x3a32f0c>
error with
<%= pie_chart @pixel.hits.group("referrer").count %>
using mongoid 3, Pixel embeds_many Hits, Hit embedded_in Pixel. referrer is a string field of a Hit.
- jdminhbg 13y ago#group is an Arel method that generates a SQL 'GROUP BY' clause in the resulting statement, not part of chartkick or mongoid.
- hayksaakian 13y agoit'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 }