gpt4 book ai didi

ruby-on-rails - Rails 4.1 向 heroku 推送 secret

转载 作者:行者123 更新时间:2023-12-04 01:38:00 25 4
gpt4 key购买 nike

Rails 4.1.0.beta1 和设计。

我正在尝试从版本控制中删除我的所有 key ,并且我已升级到 Rails 4.1 以试用这个新的 secrets.yml

试图插入 Devise 的 config.secret_key到 heroku 但它在 Assets 后失败:预编译

Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = 'EXAMPLE_KEY_HERE'
Please ensure you restarted your application after installing Devise or setting the key.

这是我的更改,我将在评论中留下旧代码。 (它有效)
devise.rb
  # config.secret_key = 'THIS_IS_A_FAKE_KEY' #<---this_is_commented_out
config.secret_key = Rails.application.secrets.devise_secret_key
secrets.yml
production:
devise_secret_key: 'THIS_IS_A_FAKE_KEY'

然后跑 heroku labs:enable user-env-compile -a myapp (不确定是否有必要)

然后当我推送到我的 fork heroku 环境时 git push forked master我收到上述错误。

我还注意到在这个 Devise 存储库中对此进行了一些讨论,所以我想我会在源存储库旁边更新我的 gem,没有区别。这是讨论的一部分( here )。

最佳答案

您可能已经将 secrets.yml 添加到您的 .gitignore 中。这是有道理的,因为您将 key 放入其中——但由于 Heroku 部署使用 git,它永远不会看到您的 secrets.yml。

一种解决方案是使用 heroku_secrets gem - 见 https://stackoverflow.com/a/22458102/2831572 .

另一种解决方案是在用环境变量的引用替换所有敏感键后,将 secrets.yml 添加到 git(即从 .gitignore 中删除它)。
所以:

production:
devise_secret_key: <%= ENV['DEVISE_KEY'] %>

然后运行 ​​ heroku config:set DEVISE_KEY='7658699e0f765e8whatever'

关于ruby-on-rails - Rails 4.1 向 heroku 推送 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21894761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com