Edit: I'm a new ruby on rails student.
Following my Git Push Heroku Master, I am running into issues with Heroku. Here is the latest and greatest, aborting the rake assets:precompile.
-----> 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
Included below are the contents of my Gemfile:
gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.1'
gem 'pg'
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
gem 'annotate'
gem 'database_cleaner'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
end
platforms :jruby do
gem 'trinidad'
gem 'jruby-openssl'
end
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
gem 'database_cleaner'
gem 'cucumber-rails', :require => false
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'
gem 'nokogiri', '~> 1.5.0'
gem 'webrat'
end
What might be the issue?
Update: I ran the rake command with --trace, and it had alerted me with a failure because the production database did not exist. I created the database, and ran --trace again, and this is what I'm currently being thrown:
Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby...]
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
In production, Rails precompiles these files to public/assets by default. The precompiled copies are then served as static assets by the web server. The files in app/assets are never served directly in production.
See the Rails 3.1+ Asset Pipeline on Heroku Cedar article. This exact scenario is covered in the Troubleshooting section.
In short, your Heroku application has a strong separation between building (including asset compilation) and running (where your application becomes available). This is consistent with the 12-factor app principles, but it means that your application cannot access any configured resources during the build phase -- including the database -- meaning ActiveRecord is unavailable during asset precompilation.
You can tell Rails not to bootstrap your application during asset compilation in config/application.rb
:
config.assets.initialize_on_precompile = false
The troubleshooting section also recommends:
If rake assets:precompile is still not working, you can debug this locally by configuring a nonexistent database in your local
config/database.yml
and attempting to runrake assets:precompile
. Ideally you should be able to run this command without connecting to the database.
I struggled with exactly the same problem, for hours tonight. After adding
config.assets.initialize_on_precompile = false
to application.rb, remember to do a
git commit
right afterwards. I forgot to do this, and Heroku had no idea I'd changed application.rb. They don't have this extra line on their troubleshooting page.
For Rails 4
Enable Heroku Labs feature to fix this problem
heroku labs:enable user-env-compile
I had this issue with Rails 4 and none of the other suggestions helped. I finally figured it out and it was due to the Rollify gem trying to connect to the database. That has been fixed in the Rollify gem, however, you may need to grab the latest source code to get the fix. I just change my gem import for Rollify to:
gem 'rolify', :git => 'git://github.com/EppO/rolify.git'
That seemed to fix the problem and I haven't had to do any of the other suggestions.
Don't forget to bundle install and commit the change to git.
Also, if that doesn't fix your problem either, you might want to start looking closely at the gems you're using and make sure none of them attempt to connect to the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With