我已经生成了简单的 Rails API 应用程序,但我遇到了 Rails.application.secrets.secret_key_base
的问题 - 它是 nil
。我在我的本地机器上启动它。
根据this article一切都应该没问题。我有正确的 app/config/credentials.yml.enc
。当我尝试使用 rails credentials:edit
编辑它时,它会正确编辑。实际内容是
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: 47ba27802a354b44c1cd0d0c624fcde2dced69ccfe62d274e9ecfc98d9e6671c4cf31a29aaf77af555d9553811a3ff15f22ab060e5ec5ffc0d29f77241368272
在所有配置文件 (/app/config/environments/*.rb
) 中,我添加了 config.require_master_key = true
- 它没有帮助。
我的实际 Rails.application.secrets
内容是 {:secret_key_base=>nil, :secret_token=>nil}
。我已将它转储到我的自定义类和 application_controller.rb
- 这两个地方的结果相同。
有什么我遗漏的想法吗?
附言。在您用重复标记此问题之前 - 请注意,我使用的是 rails 5.2,其中凭据存储已更改。
最佳答案
尝试
Rails.application.credentials.secret_key_base
secret_base_key
不同于 credentials
当您将 secret_base_key
添加到凭据时,它仅可用作凭据而不是 secret 。
关于ruby - 测试环境中 Rails.application.secrets 中缺少 secret_key_base,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52220562/