DotEnv不会在database.yml中加载值

时间:2018-09-06 17:41:03

标签: ruby-on-rails environment-variables

我已经安装了dotenv gem

  

gem'dotenv-rails',要求:'dotenv / rails-now'

我使用一些KEYS = values创建.env文件

现在,我想使用config / database.yml文件中.env中的值。

rake aborted!
SyntaxError: (erb):24: syntax error, unexpected tCONSTANT, expecting ']'
...T_DATABASE_DEVELOPMENT_PASSWORD'] ).to_s); _erbout.<< "\n\n#...
...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(erb):32: syntax error, unexpected tCONSTANT, expecting ')'
... ENV['WALLET_DATABASE_TEST_USER'] ).to_s); _erbout.<< "\n  p...
...      ^~~~~~~~~~~~~~~~~~~~~~~~~
(erb):33: syntax error, unexpected tCONSTANT, expecting ')'
...['WALLET_DATABASE_TEST_PASSWORD'] ).to_s); _erbout.<< "\n\n#...
...  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(erb):52: syntax error, unexpected tCONSTANT, expecting ')'
... _erbout.<<(( ENV['DATABASE_URL'] ).to_s); _erbout.<< "\n#\n...
...                   ^~~~~~~~~~~~
(erb):57: syntax error, unexpected tCONSTANT, expecting ')'
...WALLET_DATABASE_PRODUCTION_USER'] ).to_s); _erbout.<< "\n  p...
...^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(erb):58: syntax error, unexpected tCONSTANT, expecting ')'
...ET_DATABASE_PRODUCTION_PASSWORD'] ).to_s); _erbout.<< "\n".f...
...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(erb):59: unterminated string meets end of file
; _erbout
         ^
(erb):59: syntax error, unexpected end-of-input, expecting ')'
; _erbout
         ^
/home/kru0096/.rvm/gems/ruby-2.4.1/gems/railties-5.2.1/lib/rails/application/configuration.rb:172:in `database_configuration'
/home/kru0096/.rvm/gems/ruby-2.4.1/gems/activerecord-5.2.1/lib/active_record/railtie.rb:39:in `block (3 levels) in <class:Railtie>'
/home/kru0096/.rvm/gems/ruby-2.4.1/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

当我运行db:create时出现错误

Work Order # \d+

我在做什么错了?

1 个答案:

答案 0 :(得分:3)

您没有打勾':ENV['WALLET_DATABASE_DEVELOPMENT_USER]应该是ENV['WALLET_DATABASE_DEVELOPMENT_USER']