Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript features work on localhost but not when deployed to Heroku

Tags:

I've noticed that when I deploy to Heroku, javascript features dont work (such as Bootstrap Popover, Buttons, etc). I'm working with rails 3.2.2, ruby 1.9.3. The features work on localhost. There appear to be no errors displayed when deployed to Heroku (the features simply don't show up).

Any ideas? Thanks!

like image 545
Alex De Simone Avatar asked Apr 18 '12 18:04

Alex De Simone


People also ask

Does heroku support Javascript?

Listed on the Heroku reference page, the supported buildpacks offered are: Ruby, Node. js, Clojure, Python, Java, Gradle, Grails, Scala, Play, PHP, Go.

Does localhost work on Heroku?

Build your app and run it locally Start your app locally using the heroku local command, which is installed as part of the Heroku CLI. Your app should now be running on http://localhost:5000/.

What can be deployed on Heroku?

Heroku lets you deploy, run and manage applications written in Ruby, Node. js, Java, Python, Clojure, Scala, Go and PHP.


2 Answers

Manually precompiling worked for me.

bundle exec rake assets:precompile before you push to heroku.

like image 102
Dru Avatar answered Sep 22 '22 23:09

Dru


I had the exact same issue (I'm very new to Rails). I eventually solved the issue by rearranging the order of files within application.js:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap

For the javascripts to work in development, "require jquery" needed to be after "require twitter/bootstrap." In production, jquery needed to come first. Not sure what caused this, but it now works when deployed to Heroku.

I used these two posts:

javascript - Twitter bootstrap jquery plugins not compiled for production

twitter bootstrap drop down suddenly not working

like image 32
TaylorT Avatar answered Sep 23 '22 23:09

TaylorT