avalente1
avalente1

Reputation: 246

Rails 4 JS production issues on heroku / asset compiling

Uncaught ReferenceError: Chart is not defined

For all the places where JS is not working properly, I receive similar errors based on which JS file it is trying to read from.

In development, all my JS is reading and executing properly. In production, some of the JS is not. Here is my application.js file with comments about which are working and which aren't.

application.js

//= require jquery # working
//= require bootstrap.min # working
//= require jquery_ujs # working
//= require turbolinks # working
//= require jquery.ui.all # working
//= require jquery.sidr.min # working
//= require jquery_timepicker_addon # working
//= require infobox # working
//= require buttons # not working
//= require tooltip # not working
//= require deliveries # not working
//= require Chart# not working
//= require jquery-addressPicker # working
//= require_tree .

I run RAILS_ENV=production bundle exec rake assets:precompile and I've recently read a blog post suggesting running rake assets:clean assets:precompile but that did not solve the issues

production.rb

config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.digest = true
config.assets.version = '1.0'
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.assets.compile = false

Any help on how to debug this issue would be greatly appreciated!

deliveries.js.coffee is the only file I've written myself. The others are all from external libraries.

jQuery ->
  mixes = $('#order_mix_id').html()
  $('#order_job_id').change ->
    job = $('#order_job_id :selected').text()
    escaped_job = job.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
    options = $(mixes).filter("optgroup[label='#{escaped_job}']").html()
    if options
      $('#order_mix_id').html(options)
    else
      $('#order_mix_id').empty()

Upvotes: 0

Views: 160

Answers (1)

avalente1
avalente1

Reputation: 246

A syntax error in the infobox.js file caused files beyond it to not properly define certain variables I called in my code leading to uncaught reference errors. I'm still not sure why there was 1 file after this file that continued to work properly.

application.js

//= require jquery
//= require bootstrap.min
//= require jquery_ujs
//= require turbolinks
//= require jquery.ui.all
//= require jquery.sidr.min
//= require jquery_timepicker_addon
//= require buttons
//= require tooltip
//= require deliveries
//= require Chart
//= require jquery-addressPicker
//= require_tree .

Upvotes: 1

Related Questions