【问题标题】::rails 2.5.5 中的 MissingKeyError
【发布时间】:2022-01-23 08:37:18
【问题描述】:

我正在使用 ruby​​ 2.5.5,我正在像这样启动服务器:

RAILS_MASTER_KEY=[MY_KEY] RAILS_ENV=staging MY_DATABASE_PASSWORD=[MY_PW] bin/rails server -b 0.0.0.0

这行得通,现在我想像这样生成迁移:

RAILS_MASTER_KEY=[MY_KEY] RAILS_ENV=staging MY_DATABASE_PASSWORD=[MY_PW] bin/rails generate migration CreateJoinTableMyTable column1 foreignKey

我收到以下错误:

/path/to/.rvm/gems/ruby-2.5.5/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:96:in `handle_missing_key': Missing encryption key to decrypt file with. Ask your team for your master key and write it to /Users/BaxterStockman/empiric/hyperion-backend-webapp/config/master.key or put it in the ENV['RAILS_MASTER_KEY']. (ActiveSupport::EncryptedFile::MissingKeyError)

我还将RAILS_MASTER_KEY 写入~/.bashrc 并重新加载配置文件,但没有任何作用。

有人知道为什么会抛出这个错误吗?

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    什么是rails版本?它向您显示您应该在 app 文件夹中有一个文件 config/master.key 的错误。 credentials.yml.enc需要解密。

    只需通过询问您的同事来添加该文件,或者如果您没有,请通过生成

    EDITOR="code --wait" rails credentials:edit
    

    您可能会搜索 which EDITOR= 而不是您要使用的代码,因为我不知道。只要确保编辑器不会立即关闭,这就是为什么对于 VSCode 我必须使用 --wait 参数。

    之后,您可以将 RAILS_MASTER_KEY 放入 credentials.yml.enc

    由于出现了 Rails 5.2 凭据文件,因此您无需将密钥存储在操作系统的 ENV 变量中。

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      相关资源
      最近更新 更多