25

I'm trying to precompile the assets for my app to deploy to Heroku but have to following error.

When running:

RAILS_ENV=production bundle exec rake assets:precompile

Error:

/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

Because I use in development SQLite and in production Postgresql the following Gemfile

gem "rails", "~> 3.1.0"

group :production do
  gem 'pg'
end

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

gem 'sass-rails', "~> 3.1.0"

group :assets do
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha.0'
  gem 'html5-boilerplate'
end

I tried a lot but can't get this working.

I don't know if this is important but my database.yml looks like:

production:
  adapter: postgresql
  host: localhost
  database: db
  encoding: unicode
  username: user
  password: ''
Kieran Klaassen
  • 2,192
  • 4
  • 21
  • 25
  • 1
    have you tried this on a cedar stack? `heroku create --stack cedar` – daniel Oct 16 '11 at 22:16
  • This question is similar to https://stackoverflow.com/questions/36046092/rake-assetsprecompile-rails-env-production-error/36083793#36083793. The replies in the link (including mine) are helpful. – krazedkrish May 19 '20 at 11:01

1 Answers1

54

Old question but the accepted answer doesn't really answer the question - and I just found this in a search so I guess it's relevant.

The reason for the error is that gem 'pg' is in the production gem group.
When you run rake assets:precompile the production environment is accessed. So it is trying to load the production environment but you don't have all of the dependencies installed.

Running RAILS_ENV=production bundle exec rails server would probably give you a similar error.

I can think of two different solutions

1) Look to see if you have a .bundle/config file in your app's root. If you do, check if it says WITHOUT :production or similar. Either remove that line or the whole .bundle directory and run bundle again.

2) in Gemfile

gem :development, :production do
  gem 'pg'
end

while removing the :production group
run bundle again

Sorry to bring up old stuff...

mraaroncruz
  • 3,780
  • 2
  • 32
  • 31