如何在secrets.yml中为生产值添加秘密

时间:2014-11-02 14:23:53

标签: ruby-on-rails ruby secret-key

我正试图在开发模式下运行我的轨道,但我对此表示欢迎:

Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`

我做了rake secret并将其添加到我的secrets.yml

production:
  secret_key_base: 9c9fc2f9a0a212bb2bc5be64ec3bb722fc5ae01d79c1ed181f1b3a8e858c25f076e7845b67f75ab658947557d81c7fc08ba5bddf20860ec5d681b701be05***

这会在浏览器中生成此消息。

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.

那么如何正确地为我的secrets.yml添加秘密?

更新

我使用rake secret创建了一个新秘密。然后将其添加到export SECRET_KEY_BASE=并运行它。现在,当我echo $SECRET_KEY_BASE时,我得到了我刚才添加的秘密。当我访问本地主机时,我收到We're sorry, but something went wrong. If you are the application owner check the logs for more information.消息。

这是我的secrets.yml

development:
  secret_key_base: 89dacb16fd905ff4c6352ac93f4676a5dd6e***93edce9a5be796712d54b57b91e1335598fd73e3998fddbbdeaf3ee7f65157f2fb01ce1bea5658aa7bf745d1f

test:
  secret_key_base: cf351585b2cb43459f5a073cbfd885b3dd2af44124f13a85552***78c1cf06625c121cd3b7857f86e7fe2ba11180066753142143231c79c513e71e20372a0462

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

更新2

当我访问localhost时,这会在我的Rails日志中显示:

I, [2014-11-02T16:24:57.655671 #13782]  INFO -- : Started GET "/" for 127.0.0.1 at 2014-11-02 16:24:57 +0100
I, [2014-11-02T16:24:57.670779 #13782]  INFO -- : Processing by MoviesController#index as HTML
I, [2014-11-02T16:24:57.694266 #13782]  INFO -- : Completed 500 Internal Server Error in 23ms
F, [2014-11-02T16:24:57.697056 #13782] FATAL -- : 
ActiveRecord::StatementInvalid (Could not find table 'users'):
  app/controllers/application_controller.rb:18:in `current_user'
  app/helpers/sessions_helper.rb:26:in `logged_in?'
  app/controllers/movies_controller.rb:5:in `index'

嗯,我想我需要在生产中创建我的数据库。

现在正在运行RAILS_ENV=production rake db:create db:schema:load让我访问我的网站,尽管没有造型等。

This topic解决了没有造型的问题。我现在可以访问我的本地主机并在开发中使用我的应用程序。现在看看部署的版本是否运行得更好。

0 个答案:

没有答案