简体   繁体   English

“Chartkick 未定义”错误,使用 rails

[英]"Chartkick is not defined" error, using rails

I'm trying to make some simple charts in rails 6, using the chartkick gem.我正在尝试使用 chartkick gem 在 rails 6 中制作一些简单的图表。 I strictly followed the quickstart on chartkick.com, but I can't get the graphs to load.我严格遵循 chartkick.com 上的快速入门,但无法加载图表。 I keep getting the error "Uncaught ReferenceError: Chartkick is not defined" in my browser.我在浏览器中不断收到错误“Uncaught ReferenceError: Chartkick is not defined”。

I installed the gem.我安装了宝石。 I ran yarn add chartkick chart.js我跑了yarn add chartkick chart.js

This is my complete application.js file这是我完整的 application.js 文件

require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("chartkick")
require("chart.js")

In app/views/layouts/application.html.erb I have the line在 app/views/layouts/application.html.erb 我有这条线

 <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>

The build itself runs fine, but the js is giving me errors in my browser.构建本身运行良好,但 js 在我的浏览器中给了我错误。 Where is this coming from?这是从哪里来的? I know similar questions have been asked here, but none of them can get me any further.我知道这里有人问过类似的问题,但没有一个可以让我更进一步。

Apparently the problem was coming from something else entirely.显然,问题完全来自其他方面。 My controller inherited from ActionController::Base instead of ApplicationController, so the javascript packs didn't load from my application.html.erb.我的控制器继承自 ActionController::Base 而不是 ApplicationController,所以 javascript 包没有从我的 application.html.erb 加载。

Since I've corrected it, everything works fine now.自从我纠正了它,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM