2

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?

5 Answers 5

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)
Sign up to request clarification or add additional context in comments.

Comments

1

Manually precompiling worked for me.

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

Comments

0

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

7 Comments

Hi, thanks but yes I'm on cedar. I've been though Heroku's documentation several times, but haven't found any clues as to why my javascript isn't being run.
What other debugging have you done? If you put an alert() in application.js, does it trigger? When you go to myapp.com, is the javascript included? Does Firebug verify that the request for the asset is successful?
The javascript is included in the header, and I can go to that asset and view it and it's just the same as it is when i run the app locally and the javascript works. Inserting an alert() call doesn't work. I'll check with Firebug now, thanks!
No console errors in firebug. I can tail the log from heroku, too, and no errors there either.
The problem must be that some of the javascript is exploding when I run it on the server. But why would that be?
|
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.