【问题标题】:Error after Detecting Rails Configuration on Heroku在 Heroku 上检测 Rails 配置后出错
【发布时间】:2023-06-30 17:01:01
【问题描述】:

我的 rails 应用程序在本地运行,但是,我在部署到 Heroku 时遇到了问题。看起来它的预编译很好,但我在这里遇到一堆错误:

remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        Asset precompilation completed (1.79s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote: -----> Detecting rails configuration
remote:        $ rails runner "begin; puts %Q{heroku.detecting.config.for.assets.compile=#{Rails.application.config.try(:assets).try(:compile)}}; rescue => e; puts e; puts e.backtrace; end; begin; puts %Q{heroku.detecting.config.for.action_dispatch.x_sendfile_header=#{Rails.application.config.try(:action_dispatch).try(:x_sendfile_header)}}; rescue => e; puts e; puts e.backtrace; end; begin; puts %Q{heroku.detecting.config.for.active_storage.service=#{Rails.application.config.try(:active_storage).try(:service)}}; rescue => e; puts e; puts e.backtrace; end;"
remote:        /tmp/build_e5c8ea775fe1792a905edb1b8e4870ab/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
remote:        	from /tmp/build_e5c8ea775fe1792a905edb1b8e4870ab/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:183:in `_decrypt'
remote:        	from /tmp/build_e5c8ea775fe1792a905edb1b8e4870ab/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'

有什么想法吗?谢谢!

【问题讨论】:

  • 您遵循什么指南来将 Rails 部署到 Heroku?

标签: ruby-on-rails heroku deployment


【解决方案1】:

该错误是 Heroku 缺少用于解密凭证文件的主密钥的结果。创建一个RAILS_MASTER_KEY ENV 变量。Rails 会自动检测到它并将其用作您的主密钥进行解密。

对于heroku:$ heroku config:set RAILS_MASTER_KEY=<your-master-key-here>

这是一个very nice blog post,用于了解 Rails 凭据 API 的工作原理

【讨论】:

  • 是的。我在我的配置变量中使用 SECRET_BASE_KEY 而不是 RAILS_MASTER_KEY。谢谢!