Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Unable to use new `config/secrets.yml`

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
like image 850
Mark Boulder Avatar asked Dec 13 '25 17:12

Mark Boulder


2 Answers

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_key returns SOMEKEY in the development environment.

That's why someone created the dot_secrets gem ("Enable dot syntax on nested Rails.application.secrets")

like image 130
awendt Avatar answered Dec 15 '25 13:12

awendt


To get nested values like yours you need to use this syntax.

Rails.application.secrets.some_stuff[:secret_key]
like image 22
Mark Davies Avatar answered Dec 15 '25 14:12

Mark Davies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!