问题
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.enc
is 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