rake assets:precompile RAILS_ENV=production Error

时光毁灭记忆、已成空白 提交于 2020-08-11 05:33:54

问题


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


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/36046092/rake-assetsprecompile-rails-env-production-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!