简体   繁体   中英

"Chartkick is not defined" error, using rails

I'm trying to make some simple charts in rails 6, using the chartkick gem. I strictly followed the quickstart on chartkick.com, but I can't get the graphs to load. I keep getting the error "Uncaught ReferenceError: Chartkick is not defined" in my browser.

I installed the gem. I ran yarn add chartkick chart.js

This is my complete application.js file

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

 <%= 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. 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.

Since I've corrected it, everything works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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