【问题标题】:Ruby on Rails 6 - Credentials preventing rake tasks from loading on HerokuRuby on Rails 6 - 防止 rake 任务加载到 Heroku 的凭据
【发布时间】:2022-08-15 12:27:10
【问题描述】:

我正在尝试将应用程序从 Rails 6 升级到 Rails 6.1.6.1,但使用凭据时遇到以下错误。我的生产凭证文件包含以下内容:

aws:
  bucket_prefix: \"some-prefix\"

但是当我尝试部署到 Heroku 时,我得到以下信息:

-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     rake aborted!

 !     NoMethodError: undefined method `[]\' for nil:NilClass

 !     
 !     config.dynamic_assets.bucket_prefix = Rails.application.credentials.aws[:bucket_prefix]
 !     ^^^^^^^^^^^^^^^^

该应用程序在本地使用RAILS_ENV=production rails s 启动得很好。

有人可以指出我可能做错了什么吗?

  • 你确定那是你在 Heroku 上实际提交的文件吗?您是否尝试过运行heroku run rails credentials:edit 来验证它或检查文件校验和等简单的东西?

标签: ruby-on-rails heroku ruby-on-rails-6.1


【解决方案1】:

此错误告诉您Rails.application.credentials.aws 正在返回nil

这是什么通常意味着 Heroku 没有您的RAILS_MASTER_KEY,因此它无法访问您的credentials.yml.enc 文件。

使用 Heroku 仪表板或 CLI,您需要设置一个名为 RAILS_MASTER_KEY 的环境变量以匹配您的 master.key 文件中的键。

如需精彩的演练,请查看this SO answer

如果您设置了此环境变量,请检查以确保您没有将credentials.yml.enc 添加到您的.gitignore 列表中。

如果 Heroku 没有您的 credentials.yml.enc 文件,那么即使使用主密钥,它也无法访问其中的凭据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 2013-09-14
    • 2016-03-08
    相关资源
    最近更新 更多