Rails JavaScript views not working in production

2019-02-23 08:13发布

问题:

I'm having an unexplainable issue with my Rails app. I'm using a lot of JavaScript in all parts of the app. In development everything is working just fine, but in production it seems that the code in my javascript views is not executed.

This is particularly odd because all other JavaScript on the page works great. Custom tabs with JavaScript work. Even my custom made calendar works as expected. The only things that do not work are remote links which trigger views ending with .js.coffee.

My webkit inspector returns this when clicking a remote link: http://cl.ly/Ihyf

However, when looking at the response tab of that request it shows me nothing: http://cl.ly/Ihxs

Furthermore, the console does not show any errors. It's as if my new.js.coffee is just empty.

The view that is being called contains some simple JavaScript to show a modal:

$('#modal_container').html("<%=j render 'form' %>")
$('#modal_container').modal()

In development mode, all views load properly. I also ran rake:assets:precompile multiple times, but that didn't seem to help.

回答1:

You should move coffee-rails gem from the :assets group to the main group.