Anybody know how to set ENV variables in production.rb using the new secrets.yml?
I'm getting key: wrong number of arguments (0 for 1) for the below:
production.rb:
# DOES NOT WORK
ENV["SOME_STUFF_KEY"] = Rails.application.secrets.some_stuff.key
ENV["SOME_STUFF_SECRET_KEY"] = Rails.application.secrets.some_stuff.secret_key
# NOTE THAT THIS WORKS:
# ENV["SOME_STUFF_KEY"] = "abcdefg";
# ENV["SOME_STUFF_SECRET_KEY"] = "123456789123456789";
secrets.yml:
production:
some_stuff:
key: abcdefg
secret_key: 123456789123456789
I haven't found any information about nesting like you did with some_stuff. The release notes and all other blog posts just use flat keys as an example:
development:
secret_key_base: 3b7cd727ee24e8444053437c36cc66c3
some_api_key: SOMEKEY
Rails.application.secrets.some_api_keyreturns SOMEKEY in the development environment.
That's why someone created the dot_secrets gem ("Enable dot syntax on nested Rails.application.secrets")
To get nested values like yours you need to use this syntax.
Rails.application.secrets.some_stuff[:secret_key]
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