Search code examples
javascriptruby-on-railsproductionturbolinks

Javascript works locally, but no longer works when deployed to Heroku. (With turbo links.)


For some reason my javascripts are not working on Heroku. I know that this has something to do with Turbolinks, but I'm not sure what could be causing it.

Gemfile:

gem 'turbolinks', '~> 1.3.0'
gem 'jquery-turbolinks'

As you can see, I am using the query-turbolinks gem. Locally, everything works, but when deployed all of my Javascript is broken as if I haven't loaded my javascripts correctly.

Maybe I need to apply this code to all of my javascripts?

var ready;
ready = function() {

  ...your javascript goes here...

};

$(document).ready(ready);
$(document).on('page:load', ready);

I wonder why it is working in development but not in production...


Solution

  • try with updating this in production.rb

    config.assets.compile = true
    config.serve_static_assets = true