Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is javascript not working on deployment to heroku?

After deploying a Rails app to Heroku, no javascript functions are working.

The files appear to have been compiled (though its not easy to see in the minified file).

What is a logical process of steps to work out why the javascript is not working (it works fine in production).

Thanks

like image 668
Andy Harvey Avatar asked Jun 08 '12 08:06

Andy Harvey


2 Answers

This problem is associated with asset pipeline. You should compile assets.

To solve it, Turn config.assets.compress to true in config/environments/production.rb,

ie

  config.assets.compress = true

Then run RAILS_ENV=production bundle exec rake assets:precompile .

Push the code again.

like image 57
Shamith c Avatar answered Oct 21 '22 17:10

Shamith c


Sometimes I have issues because of the asset pipeline and my misunderstanding of it. So what I do just to make sure things are being packaged up correctly is just put in a simple alert when the page loads (put it on some random page users can't get to, etc)

alert('some-unique-string')

Push the code up to the server. Then in chrome bring up the page and use the dev tools, goto the "scripts" tab. From there you can search for the string some-unique-string since your string literal wont be minified. If you don't see that then you know your javascript isn't being included for some reason.

That at least will give you a starting point.

like image 37
Dty Avatar answered Oct 21 '22 18:10

Dty