0
votes

I want to deploy a spree app to heroku and in order to do that I need to precompile my assets locally I did

heroku addons:create heroku-postgresql 

then I added config/application.rb

config.assets.initialize_on_precompile = false

my database.yaml file is

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  host: localhost
  database: anzels_development
  username: anzels
  password: 1234

test:
  <<: *default
  host: localhost
  database: anzels_test
  username: anzels
  password: 1234


production:
  adapter: postgresql
  encoding: unicode
  database: anzels_production
  pool: 5
  password:

and whenever I run

sumeet@sumi-pc:~/anzels$ rake assets:precompile RAILS_ENV=production

I get an error rake aborted!

ActiveRecord::NoDatabaseError: FATAL:  role "sumeet" does not exist
/home/sumeet/anzels/config/environment.rb:5:in `<top (required)>'
PG::ConnectionBad: FATAL:  role "sumeet" does not exist
/home/sumeet/anzels/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)

config/enviormenr.rb

# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

please help

2
Your config/environment.rb would be useful.Thomas R. Koll
@ThomasR.Koll posted my config/environment.rbSumeet Masih
Just create a postgres role with name "sumeet"xor
What rails version? Also, you don't need to precompile assets for heroku - they will detect if you did and they'll precompile them for you. Please refer to documentation: devcenter.heroku.com/articles/rails-asset-pipelineBroiSatse
@adil thanks your suggestion workedSumeet Masih

2 Answers

4
votes

In local computer you are trying to run

rake assets:precompile RAILS_ENV=production

but this requires your local compute to have config/database.yml with the config mentioned by @thieu-nguyen

so add the following in

username: $PRODUCTION_DB_USER

password: $PRODUCTION_DB_PASS

under production in config/database.yml

then add the environment for you local computer as

PRODUCTION_DB_USER=anzels

PRODUCTION_DB_PASS=1234

and for heroku as

PRODUCTION_DB_USER=user

PRODUCTION_DB_PASS="" (empty)


ANOTHER EASIER WAY IS

username: anzels

password: 1234

to production in config/database.yml **JUST BEFORE assests precompilation ** then run command

git checkout config/database.yml

JUST BEFORE GIT COMMIT command the idea is to not to commit the username and password but temporarily edit it for assests precompilation purpose only

0
votes

Please add username and password to production config in database.yml or you need to create new role for postgres with name "sumeet".

production:
  adapter: postgresql
  encoding: unicode
  database: anzels_production
  pool: 5
  username: anzels
  password: 1234