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: ''
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.
rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.
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...
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