Rails 5.2 application secrets empty at Heroku

泄露秘密 提交于 2020-03-05 04:15:08

问题


I deployed to Heroku with success but there is an issue with credentials. I added RAILS_MASTER_KEY env variable at Heroku app CONFIG VARS section and copy-pasted the value from my app master.key file:

Then when I check its value from Heroku console, it is still nil:

Loading production environment (Rails 5.2.3)
irb(main):001:0> Rails.application.secrets.secret_key_base
=> nil
irb(main):002:0> Rails.application.secrets
=> {:secret_key_base=>nil, :secret_token=>nil}
irb(main):003:0> 

But when I check it other way:

ENV['RAILS_MASTER_KEY']
=> "sdfghjklm.......1a0befa6139"

it is displayed correctly.

What am I missing?


回答1:


I figured out myself, - I followed a Pluralsight tutorial on Rails API and it used the old way to get Rails secrets:

Rails.application.secrets.secret_key_base

Starting from Rails 5.2 there is no more secrets.yml file and the right way to get the env variables saved in credential.yml.encis as follows:

Rails.application.credentials.dig(:secret_key_base)

After updating the corresponding code, everything works as needed. Hope this helps.



来源:https://stackoverflow.com/questions/56889272/rails-5-2-application-secrets-empty-at-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!