Monday, January 23, 2012

Rails 3.2 development environment asset issue

I just tracked down and dealt with an issue I was having after upgrading to rails 3.2. After the upgrade assets (css, javascript) were not updating unless I restarted the server process. Took me a while to track down the issue but I finally tracked it down to asset fingerprinting. Asset fingerprinting is off by default in the development environment but I had turned it on to debug an issue a long time ago.

If you are having similar problems make sure that you have the following line in "config/environments/development.rb"

  config.assets.digest = false

Friday, January 20, 2012

Rails 3.2 on Heroku asset:precompile issue

I just upgraded to Rails 3.2 and found that the asset precompile step of the release was not working properly.

Here is the output I was getting:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       could not connect to server: Connection refused
       Is the server running on host "" and accepting
       TCP/IP connections on port 5432?
       Tasks: TOP => environment
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation

The issue was rails was trying to connect to the database during the precompile process, and heroku is setup not to allow that. I am guessing that this issue is due to a change in the rails initialization setup in rails 3.2.

It turns out that the fix for this is very simple as long as you don't actually need to connect to the database during asset precompiling. All you need to do is add the following line to 'config/application.rb'

config.assets.initialize_on_precompile = false

Additional Resources