Thursday, 10 May 2012

First Time Heroku, Precompiling Assets

provides in the , and is well known as a host for apps. Last week, my first opportunity arrived to find out whether Heroku is as good as they say. I wasn't disappointed.

Following the documentation, everything progressed smoothly: signing up, installing Heroku Toolbelt, initial login, creating the cedar stack and the final push — except asset compilation. By default, Heroku continues even if asset compilation fails. So always read the output carefully:

$ git push heroku master
...
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.2
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> 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 "127.0.0.1" 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
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
-----> Rails plugin injection
...

One simple way around an asset compilation issue is to:

  1. Compile locally
    $ bundle exec rake assets:precompile
    
  2. Commit assets to git
    $ git add -f public/assets/
    $ git commit -m "Precompile public assets"
    
  3. Push
    $ git push -f heroku master
    

And — after heroku run rake db:migrate — everything's great

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Detected manifest.yml, assuming assets were compiled locally
-----> Rails plugin injection

or at least for me...

No comments:

Post a Comment