rake assets:precompile RAILS_ENV=production Error
Asked Answered
G

2

0

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

Gile answered 16/3, 2016 at 20:17 Comment(5)
Your config/environment.rb would be useful.Levorotation
@ThomasR.Koll posted my config/environment.rbGile
Just create a postgres role with name "sumeet"Farcical
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-pipelineAssailant
@adil thanks your suggestion workedGile
V
4

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

Vipul answered 18/3, 2016 at 11:59 Comment(0)
I
0

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
Isbell answered 17/3, 2016 at 2:53 Comment(4)
production db does not have a user or passwordGile
But you want to compile assets in your local, right?Isbell
yes I do, but by doing this I get an authentication errorGile
You just need to compile assets in your local, then push it to heroku, so just config your production config like developemnt enviroment (database name, username, pass) :)Isbell

© 2022 - 2024 — McMap. All rights reserved.