未定义的方法`group_by_day' - rails 3.2 [英] undefined method `group_by_day' - rails 3.2

查看:37
本文介绍了未定义的方法`group_by_day' - rails 3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 chartkick 制作用户注册数量(每天)的折线图,这是一个简单的单行代码,但出现错误

I want to make a line-chart of the number of User signups (per day) using chartkick, it is a simple one line code but it is giving an error

`undefined method `group_by_day' for #<Class:0x00000004b4fbf0>`

在我看来我有

<%= line_chart User.group_by_day(:created_at).count %>

错误日志:

Rendered admin/dashboards/index.html.erb within layouts/application (145.2ms)
Completed 500 Internal Server Error in 1018ms

NoMethodError - undefined method `group_by_day' for #<Class:0x00000004b4fbf0>:
  activerecord (3.2.14) lib/active_record/dynamic_matchers.rb:55:in `method_missing'
  app/views/admin/dashboards/index.html.erb:38:in `_app_views_admin_dashboards_index_html_erb___3330517857505238097_39214860'
  actionpack (3.2.14) lib/action_view/template.rb:145:in `block in render'
  activesupport (3.2.14) lib/active_support/notifications.rb:125:in `instrument'
  actionpack (3.2.14) lib/action_view/template.rb:143:in `render'
  actionpack (3.2.14) lib/action_view/renderer/template_renderer.rb:48:in `block (2 levels) in render_template'
  actionpack (3.2.14) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (3.2.14) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.14) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.14) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.14) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'

推荐答案

要支持 group_by_day,您需要捆绑另一个 gem:groupdate 来自 Chartkick 的同一作者.

To have group_by_day supported, you need to bundle another gem: groupdate from the same author of Chartkick.

这篇关于未定义的方法`group_by_day' - rails 3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆