Search code examples
javascriptruby-on-railsherokuchartkickuglifier

Chartkick is not loading in heroku, but works in local


I created a new rails application and configured the chartkick , the chart is loading good in local. But its not loading when pushed to heroku.

Why its loading in development without any error and not loading in heroku? Any clues?

Application.js

//= require Chart.bundle
//= require chartkick
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .

Gemfile

gem 'chartkick'

Applicaion.html.erb

 <!DOCTYPE html>
<html>
<head>
  <title>Testp</title>
  <%= csrf_meta_tags %>
  <%= csp_meta_tag %>
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<%= yield %>
</body>
</html>

index.html.erb

<h1>Test#index</h1>
<%= column_chart [['Sample1', 52.9], ['Sample2', 27.7], ['Sample3', 1.6]]%>

enter image description here


Solution

  • As I pointed out in comments, when facing issues like "something not defined" one should try to disable Uglifer (or any minification tool). Minification can break your code pretty often because it messes with variable names.

    I don't have general solution for this issue (minification) but you can always google your specific case: https://github.com/ankane/chartkick/issues/347