Rails 5 - JS not working in production environment (only)
<p>I am struggling.</p>

<p>I have rails 5 app with a series of js files in my app/assets/javascripts folder. The js in those files works just fine in the development environment, but when I publish on heroku, it stops working.</p>

<p>I can see from the chrome inspector, that the application.js file that is visible from the network tab shows the content of the js files in my app. That js just doesnt seem to do anything in production. No console errors appear from the chrome console inpsector.</p>

<p>I can see from <a href="https://stackoverflow.com/questions/32502472/rails-4-in-production-my-javascript-is-loaded-but-does-not-work-while-it-works/40875845?noredirect=1#comment68966803_40875845">this post</a> that there are a series of things to try. I've tried all of them. I've even made a completely new app and added the js files on at a time to see if there is a tipping point where something is required in a different order to something else (mostly guessing) - but that does nothing to fix the problem.</p>

<p>I can see from <a href="https://www.reinteractive.net/posts/116-12-tips-for-the-rails-asset-pipeline" rel="nofollow noreferrer">this article</a> that one suggestion is to:</p>

<pre><code># Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
</code></pre>

<p>and then try:</p>

<pre><code>rake assets:clean assets:precompile
</code></pre>

<p>I've tried each of these suggestions and still can't find the problem.</p>

<p>If there were an error in the way I've written the js, I would expect that to be exposed in both my development and production environment console inspectors in chrome. There are no errors showing in either environment. </p>

<p>If there were a problem with the production environment reading the js file, I'm confused about why I can word search for the words used in the js file in the file I can open from the network tab and see the correct text.</p>

<p>How do I go about solving this problem?</p>

<p>My relevant files are:</p>

<p>app/assets/javascripts/application.js</p>

<pre><code>//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery-fileupload/vendor/jquery.ui.widget
//= require jquery-fileupload/jquery.iframe-transport
//= require jquery-fileupload/jquery.fileupload
//= require bootstrap-sprockets
//= require moment
//= require bootstrap-datetimepicker
//= require pickers
// require underscore
// require gmaps/google
//= require markerclusterer
//= require cocoon
//= require cable
//= require_tree .
</code></pre>

<p>config/initializers/assets.rb</p>

<pre><code># Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path
# Rails.application.config.assets.paths &lt;&lt; Emoji.images_path

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
</code></pre>

<p>config/production.rb</p>

<pre><code>  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false
</code></pre>

<p>The relevant file that is not working in the production environment is saved in app/assets/javscripts/stance/commercial.js (so it should be identified in application.js by //= require_tree.</p>

<p>That file has:</p>

<pre><code>jQuery(document).ready(function() {
   jQuery('[name="organisation[commercial_attributes][standard_financial_split]"]').on('click', function() {
      if (jQuery(this).val() == 'true' ) {
          jQuery('#commercial_standard_financial_split_content').removeClass('hidden');
      } else {
          jQuery('#commercial_standard_financial_split_content').removeClass('hidden').addClass('hidden');
      }
   });

});
</code></pre>

<p>Can anyone help with a process for getting js to work in the production environment?</p>

<p>I am out of suggestions for things to try and this isn't the sort of thing that the tutorials, code schools (I am a student in code school, go rails, udemy and have a million books), but can't find an reference point from which to start in solving this problem.</p>