I have been trying every possible way of executing the following:
@events.group(:name).count
in my index.html.erb page using chartkick to display the total number of events. I keep running into errors like nil:method and each_pair unknown method. What would be the mongoid equivalent of a group or count? I have tried:
@events.only(:name).group
@events.where(name: @events.name).aggregate
@events.only(:name).aggregate
@events.only(:name).group_by(&:_id)
Not sure what would work...any help will be appreciated. My controller is the following:
class EventsController < ApplicationController
before_filter :authenticate_user!
def index
@domain = Domain.find_by(id: params[:domain_id])
@events = @domain.events
end
end
My view is the following:
<h1>Events</h1>
<%= line_chart @events.all.aggregrate %>
<%= line_chart @events.group_by_day(&:created_at).count %>
I am using Rails 4 with Mongoid 4.0 and Chartkick.