Javascript features work on localhost but not when deployed to Heroku

心已入冬 提交于 2019-11-27 09:02:44

I also had similar problem but the problem was happening on localhost as well.

You are probably using rails-bootstrap gem. It installs a file bootstrap.coffee.js This file was culprit. It had .popover use and relevant plugin was not included. I commented that out as I was not using it anyway but you should consider including the popover plugin for bootstrap.

Manually precompiling worked for me.

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

TaylorT

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

Check your production.rb file. I believe the line needs to be:

config.assets.compile = true

I believe this gets set to false by default.

Remember that everything that you would normally do on localhost, you must be doing with heroku. Make sure you heroku run rake assets:precompile.

Checked the minified js for my app, and popover was twice in the file.

Be sure that only one of bootstrap and boostrap-sprockets is declared in your javascript assets

From the docs:

bootstrap-sprockets and bootstrap should not both be included in application.js.

bootstrap-sprockets provides individual Bootstrap Javascript files (alert.js or dropdown.js, for example), while bootstrap provides a concatenated file containing all Bootstrap Javascripts.

Be sure that only one of bootstrap and bootstrap sprockets

Refs: bootstrap-sass github issue and here.

Updating sprockets worked for me: bundle update sprockets

If you've already tried heroku run rake assets:precompile and the JS still isn't working, try doing heroku restart to restart the server after precompiling assets.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!