Generating a new secrets.yml file
Asked Answered
G

2

17

I'm trying to clone a rails repository from github, but it doesn't have a secrets.yml file. When I try to run the app from rails server, I get the error

Missing secret_key_base for 'development' environment, set this value in config/secrets.yml

I know what the structure of the file is supposed to look like, but is there a way for me to generate keys to use the development environment?

Gabar answered 26/8, 2015 at 18:58 Comment(0)
R
29

This rake task generate secret for you:

bundle exec rake secret

Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)

All rake tasks:

bundle exec rake -T 

The secrets.yml file(note the indentation):

development:
  secret_key_base: d140269c106b6d064cdd670a5aace0bbbb1400de545377a47836dbdab8104f2fdf0ab87e6b7982819d1bcc2ccf6a5f093985a0895970f01f30b0b15378a090e9
  some_key: 338a3312d82
  some_secret: f5d9c3214e7b
  other_environment: development
  other_password: password

production:
  secret_key_base: d140269c106b6d064cdd670a5aace0bbbb1400de545377a47836dbdab8104f2fdf0ab87e6b7982819d1bcc2ccf6a5f093985a0895970f01f30b0b15378a090e9
  some_key: 338a3312d82
  some_secret: f5d9c3214e7b
  other_environment: development
  other_password: password
Rakel answered 26/8, 2015 at 19:0 Comment(3)
your rails server run in the development environment?Rakel
I made the mistake of using a file called secrets.sample.yml instead of secrets.yml. It's working now. Thanks for the answer, that command was exactly what I needed!Gabar
Thanks, had to wait for StackOverflow's timer to allow me to do soGabar
B
16

In Rails 5 you can simply type.

rails secret

This will generate a new key for you. Just copy the key and put it in your secrets.yml file

development:
  secret_key_base: <Generated key>
Bitters answered 8/5, 2017 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.