I have this code in the controller
def index
puts Rails.application.credentials.admin_email
if (current_admin && current_admin.email == Rails.application.credentials.admin_email)
#do this
else
#do that
end
end
The else branch always happens. I believe this is because I am not getting the string from the encrypted file back, as the puts line never prints anything.
When I type Rails.application.credentials.admin_email
in the rails console, I get the correct response, "[email protected]"
My config/credentials.yml.enc
file looks like the following:
admin_email: [email protected]
I have also tried changing the config/credentials.yml.enc
file to be:
development:
admin_email: [email protected]
And have changed the code to be
puts Rails.application.credentials[:admin_email]
if (current_admin && current_admin.email == Rails.application.credentials[:admin_email]
Then in the rails console I get the correct [email protected]
using
Rails.application.credentials[:development][:admin_email]
, but still nothing shows up from the development code when running rails s
.
Looks like you might have a typo/ copy paste error.
If you still have the credentials file in this format:
development:
admin_email: [email protected]
Then you should be accessing it with
Rails.application.credentials.development[:admin_email]
In your question though under "And have changed the code to be" you still have the old version:
puts Rails.application.credentials[:admin_email]
if (current_admin && current_admin.email == Rails.application.credentials[:admin_email]
This should be:
puts Rails.application.credentials.development[:admin_email]
if (current_admin && current_admin.email == Rails.application.credentials.development[:admin_email]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With