javascript not running on heroku with rails 3.1

血红的双手。 提交于 2019-12-11 03:38:22

问题


I've migrated a rails 3.0 app to 3.1 on Heroku. It's running on the cedar stack and everything is fine except that the app's javascript won't run. The application.js file is compiled and looks just as it should. It's accessible by going to myapp.com/assets/application.js. It just doesn't get run!

If I run the app locally, the javascript works, so I suspect that there must be some simple configuration issue that I'm missing. Here's my production.rb file:

FloridaBirdTrail::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify
end

edit

Replacing the contents of production.rb with that of development.rb has allowed at least some of my javascript to run (gmap3 isn't working, for some reason). But which of the settings is making the difference?


回答1:


Open your application.rb file and make sure your Bundler require statement looks like the following:

Bundler.require *Rails.groups(:assets)

By default it looks like

# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)



回答2:


Manually precompiling worked for me.

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




回答3:


Were you sure to switch Heroku to the Cedar stack? Here are some docs for upgrading

http://devcenter.heroku.com/articles/rails31_heroku_cedar#upgrading_from_previous_rails_31_releases

http://devcenter.heroku.com/articles/cedar




回答4:


I had some Javascript problems (server-side on Heroku, locally everything was fine) that went away when I * moved all my Javascript into a separate file instead of application.js
* removed require_tree from application.js and instead called up every javascript I wanted by name
* removed bootstrap.js from my app/assets/javascript folder

My guess is that compilation somehow screws things up.




回答5:


I hope you did a local pre-compilation of assets before your latest Heroku push (as advised in one of the responses above). Please check if your system is blocking the execution of JavaScripts. For this, open up the console while you are on your Heroku app, and check for exceptions. In case you see exceptions related to JavaScripts being blocked, that could be the issue. In my case, the same happened, and unfortunately, I was not able to do anything about it, as I didn't have admin privileges.



来源:https://stackoverflow.com/questions/7489136/javascript-not-running-on-heroku-with-rails-3-1

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