【发布时间】:2020-09-07 11:03:47
【问题描述】:
我正在开发一个 Rails 6 应用程序,我正在尝试为我的应用程序中的图表设置 Chartkick。
我是这样安装 Chartkick 的:
-
对于 Rails 6 / Webpacker,运行:
yarn add chartkick chart.js -
在
app/javascript/packs/application.js中添加:require("chartkick") require("chart.js")
3 安装Groupdate 以使用 group_by_day 方法
gem 'groupdate'
然后运行bundle install。
但是,当我将此行添加到仪表板视图时:
<%= line_chart @products.group_by_day(:created_at).count %>
使用@products 变量显示产品图表:
class Admins::DashboardController < ApplicationController
before_action :authenticate_admin!
# GET /dashboards
# GET /dashboards.json
def index
@products = Product.all
end
end
我收到以下错误:
undefined method `line_chart'
我想知道我做错了什么。
【问题讨论】: