无法解密 config/credentials。yml.enc。也许您传递了错误的密钥?

Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?

我最近删除了我的本地项目,但做了一个 git 克隆并从我上次提交的地方开始。当我尝试将图像上传到已配置的 AWS 时,出现此错误:

Aws::Sigv4::Errors::MissingCredentialsError in RentalsController#create


Cannot load `Rails.config.active_storage.service`: missing credentials, provide credentials with one of the following options: - :access_key_id and :secret_access_key - :credentials - :credentials_provider

我试图查看我的 credentials.yml 文件是否有任何错误,但是当我输入此命令时:

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

...我收到此错误:

Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?

可能是什么问题?

您缺少 master.key

当您创建一个新项目时,rails 将设置 credentials.yml.enc 和匹配的 master.key 文件以访问凭据。 master.key 文件也将自动添加到 gitignore,因此如果您删除本地项目并再次克隆它,您的 master.key 将会丢失。

解决此问题的唯一方法是设置新的 credentials.yml.enc 并再次将您的 AWS 凭据添加到其中。

首先您需要删除现有的 credentials.yml.enc,然后是 运行: rails credentials:edit 创建一个新的。