Ruby on rails 带有master.key数字海洋部署的Rails 5.2:ActiveSupport::MessageEncryptor::InvalidMessage:ActiveSupport::MessageEncryptor::InvalidMessage

Ruby on rails 带有master.key数字海洋部署的Rails 5.2:ActiveSupport::MessageEncryptor::InvalidMessage:ActiveSupport::MessageEncryptor::InvalidMessage,ruby-on-rails,capistrano,Ruby On Rails,Capistrano,我已经将RubyonRails应用程序从Rails 5.1.2迁移到Rails 5.2.0,以使用加密的机密。应用程序已成功部署到Digital Ocean Ubuntu服务器。但当我进入浏览器访问时,它会显示以下日志 ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage /home/deploy/apps/GeekyCricket/shared

我已经将RubyonRails应用程序从Rails 5.1.2迁移到Rails 5.2.0,以使用加密的机密。应用程序已成功部署到Digital Ocean Ubuntu服务器。但当我进入浏览器访问时,它会显示以下日志

    ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:184:in `_decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:79:in `decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:42:in `read'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:21:in `read'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:33:in `config'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:38:in `options'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
  (erb):12:in `<main>'
我使用rails credentials:edit添加了加密的机密,它创建config/credentials.yml.enc和master.key


我还在ubuntu服务器的/app\u name/shared/config/上添加了master.key文件,还放置了一个env变量RAILS\u master\u key。但是仍然会出现这个错误,我不知道我在这里遗漏了什么。

解决方案A和B是不同的解决方案。只要选择对你有好处的

A.从持续集成中部署 一,。编辑deploy.rb

二,。将RAILS\u MASTER\u KEY添加为变量

Bmaster.key的使用 一,。编辑deploy.rb

二,。上载master.key与:链接的_文件


让我们假设应用程序的根路径是/home/deploy/awome project。我们需要做的就是将密钥文件上传到/home/deploy/awesome project/shared/config/master.key。

如果它解决了您的问题,您能给出正确的答案吗,@talha junaid?否则,我会帮你的。你解决了吗?我真的很想帮你,你解决了吗?我真的很想帮你。ThxThanks@Boris,我解决了之前没有回复你的问题。我已经解决了这个问题。但我不认为default_env是一个好方法,因为最终我们必须在gitlab/github上推送deploy.rb,并且我们的主密钥可能会被公开,我们肯定不想这样做。不过,这将是一个很好的设置:default_env,{RAILS_MASTER_KEY=>env[RAILS_MASTER_KEY]}你说得对,@talha junaid。所以,我要改变我的答案。@TalhaJunaid:你能把你的答案贴在这里吗?这会有帮助的。我也遇到了这种问题,没有找到任何正确的解决方案。@AkshayBorade,你能检查一下答案吗?谢谢。@AkshayBorade很抱歉没有提前回复您,上述解决方案是否解决了您的问题?
set :default_env, {
  "RAILS_ENV" => "production",
  "RAILS_MASTER_KEY" => ENV["RAILS_MASTER_KEY"]
}
append :linked_files, "config/master.key"