rake assets:precompile RAILS_ENV=生产错误

rake assets:precompile RAILS_ENV=production Error

我想将 spree 应用程序部署到 heroku,为此我需要在本地预编译我的资产 我做到了

heroku addons:create heroku-postgresql 

然后我添加了 config/application.rb

config.assets.initialize_on_precompile = false

我的 database.yaml 文件是

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:

每当我 运行

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

我收到一个错误 耙子中止!

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!

请帮忙

请将 usernamepassword 添加到 database.yml 的生产配置中,或者您需要为名称为 "sumeet".

的 postgres 创建新角色
production:
  adapter: postgresql
  encoding: unicode
  database: anzels_production
  pool: 5
  username: anzels
  password: 1234

您正在尝试在本地计算机上 运行

rake assets:precompile RAILS_ENV=production

但这需要您的本地计算具有 config/database.yml 以及 @thieu-nguyen

提到的配置

所以在

中添加以下内容

username: $PRODUCTION_DB_USER

password: $PRODUCTION_DB_PASS

正在 config/database.yml

生产中

然后将本地计算机的环境添加为

PRODUCTION_DB_USER=anzels

PRODUCTION_DB_PASS=1234

对于 heroku 为

PRODUCTION_DB_USER=user

PRODUCTION_DB_PASS="" (empty)


另一种更简单的方法是

username: anzels

password: 1234

to production in config/database.yml **就在资产预编译之前** 然后 运行 命令

git checkout config/database.yml

就在 GIT COMMIT 命令之前 这个想法是不提交用户名和密码,而是临时编辑它仅用于评估预编译目的