Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Farhan Daredia
Farhan Daredia
5,912 Points

Deploying Treebook to Heroku (rake aborted! and Connection refused)

Hey there,

I'm dealing with some issues trying to deploy Treebook to Heroku for the first time. I've gone through a bunch of the discussions in the forum for people that have had similar issues and made the changes as instructed... Not working out :(

So... here's my error:

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_b88df55d-3f7f-4711-b606-75b6850d125d/Rakefile:7)
       DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_b88df55d-3f7f-4711-b606-75b6850d125d/Rakefile:7)
       Connecting to database specified by DATABASE_URL
       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.
 !

 !     Push rejected, failed to compile Ruby app

To git@heroku.com:pacific-coast-8073.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:pacific-coast-8073.git'

One thing to note is that whenever I need to do a rake command in the console, I have to pre-pend it with bundle exec, don't know if that's relevant here.

Relevant sections of my Gemfile (Added pg and 'rails_12factor') https://devcenter.heroku.com/articles/getting-started-with-rails4#heroku-gems

source 'https://rubygems.org'

gem 'rails', '3.2.6'
group :production do
    gem 'rails_12factor'
        gem 'pg'
end

group :development, :test do
    gem 'sqlite3'
end

Changed production section of database.yml file to postgresql: https://teamtreehouse.com/forum/issues-trying-to-push-to-heroku

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: treebook
  pool: 5
  timeout: 5000

In the application.rb file, config.assets.initialize_on_precompile = false was already in the bottom of the file:

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
    config.assets.initialize_on_precompile = false
  end
end

However there is this part of the file at the top that I'm curious about:

if defined?(Bundler)
  # 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)
end

I've tried commenting out the first one and using the second one instead. Also tried commenting out both and adding

config.assets.initialize_on_precompile = false

in that code block instead.

I bundle install every time after making changes, then commit to git, and then try pushing to Heroku but it keeps giving me the same error.

I've also done it with Jason's suggestion: https://teamtreehouse.com/forum/cannot-install-pg-needed-for-heroku

bundle install --without=production

Tried doing his other suggestion: https://teamtreehouse.com/forum/precompiling-assets-failed-enabling-runtime

Hey George Petrov that's a really weird error! Try following along here https://devcenter.heroku.com/articles/rails-asset-pipeline and see if that helps. There's an option to precompile the assets locally before pushing up to Heroku that might work for you.

RAILS_ENV=production bundle exec rake assets:precompile

Gives me this error...

/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby /usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
TypeError: 'undefined' is not an object (evaluating 'scope.active')
  (in /Users/FarhanDaredia/Projects/treebook/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Anybody have any thoughts on what I'm doing wrong?

Thanks! Farhan

Rodrigo Soares
Rodrigo Soares
2,460 Points

Have you ever pushed anything successfully to Heroku or this is the first push and you're not even getting able to do the first one?

3 Answers

Rodrigo Soares
Rodrigo Soares
2,460 Points

Because I assume your using Rails 4 you should add those 2 gems to your production group in order to correctly interact with Heroku:

    gem 'rails_log_stdout',           github: 'heroku/rails_log_stdout'
    gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'

My application.rb file does not contain the if condition on the bundler. My application.rb looks like this :

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Treebook
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
    config.assets.initialize_on_precompile = false
  end
end

Try that and let me know!

Good luck!

Artem Prytkov
Artem Prytkov
11,932 Points

I encountered same problem. 1) Make sure you passed credentials from your heroku db to config/database.yml (production settings). 2) bundle exec rake assets:precompile was enough for me to pass this step

I figured out how to get around the Deprecation Warning, which I believe was also making my app crash before it could load on Heroku.

Check out this: http://stackoverflow.com/questions/13864945/rails-2-3-style-plugins-why-the-deprecation-warnings

These are the steps that resolved it for me:

Add the line: gem 'rails_12factor' to your gemfile

On the top of your gemfile add the line: ruby '2.0.0' (if that's the version you're using - note that you don't put the word "gem" beside " ruby '2.0.0'"- this may be obvious to you, but I'm a newbie so it wasn't to me)

Then, in your terminal:

bundle install, git add . , git commit, git push origin master, git push heroku master, heroku run rake db:migrate

And it should be up and running.