Reputation:
I'm having trouble loading my .js files in production on Heroku.
I know the files are being picked up from the asset pipeline as they are working in development just fine but I am unable to get the .js working in production.
I have created /assets/javascripts/notification.js
containing:
$(document).ready(function() {
$("span").click(function() {
$(".notice").delay(200).fadeOut(2000, function() {
});
});
});
My /assets/javascripts/application.js
file contains:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
in development, this works great.
When I deploy to Heroku, I can see that the code is displayed within a single application.js
file, except the document ready function is stripped out, see below production .js file:
<script src="/assets/application-b9a733c3cc0929ae852e45a6c3a2a5f6.js" data-turbolinks-track="true"></script>
My config/production.rb
contains:
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = true
Upvotes: 0
Views: 394
Reputation: 18784
If you install the rails_12factor gem as Heroku Recommends it will automatically run rake assets:precompile
on deploy (through a gem dependency named rails_serve_static_assets).
It may skip this step if it sees a public/assets/manifest.* file or a /public/assets directory, which tells it you've already compiled the assets, and it doesn't need to be done again.
Upvotes: 1