javascriptruby-on-railschartkick

"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.


Solution

  • 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.