Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

CodeParody asked in Rails

Hi,

im newie with Ruby and Rail. Right now im following Book Two from Daniel Kehoe. I stucked with SECRET_KEY_BASE.

Ruby -v : 2.4.1
Rails -v: 5.1.6

After I restart Puma:

Puma caught this error: Missing secret_key_base for 'development' environment, set this value in config/secrets.yml (RuntimeError)
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/railties-5.1.6/lib/rails/application.rb:510:in validate_secret_key_config!'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/railties-5.1.6/lib/rails/application.rb:247:in
env_config'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/railties-5.1.6/lib/rails/engine.rb:692:in build_request'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/railties-5.1.6/lib/rails/application.rb:518:in
build_request'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/railties-5.1.6/lib/rails/engine.rb:521:in call'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/puma-3.12.0/lib/puma/configuration.rb:225:in
call'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/puma-3.12.0/lib/puma/server.rb:658:in handle_request'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/puma-3.12.0/lib/puma/server.rb:472:in
process_client'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/puma-3.12.0/lib/puma/server.rb:332:in block in run'
/Users/marque/.rvm/gems/ruby-2.4.1@learn-rails/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in
block in spawn_thread'

I changed few files like: .bash_profile; .profile and ofc. secrets.yml. But still without change

I found more then one .bash_profile. So, I dont know which one is the right one.
After I use command echo $SECRET_KEY_BASE. I'm getting empty line.



secrets.yml

development:
email_provider_username: <%= ENV["Blabla"] %>
email_provider_password: <%= ENV["Blabla"] %>
domain_name: example.com
mailchimp_api_key: <%= ENV["96d57479cfasfafafa"] %>
mailchimp_list_id: <%= ENV["e3ettq"] %>
owner_email: <%= ENV["Blabla@ddd.ua"] %>
secret_key_base: a720feb188850db37612fad94b21e71fb869e9843c6b4da34803f65097b8f0cb30e1b46190ea0838d10dd9860bac3329937981787da4dd20827c95efcaa51ac5

test:
secret_key_base: 2eef31eaf47d6bbcc044ac5b29a115d60e12a33e60230f75d7d73c6c8c486b3ce4c346093e8abbdfa09d1097c643970bba4c4ff0299f4ae450b60160250bb011

** production:**
secret_key_base: <%= ENV["3a20ffed3e7f05400c322f06eddfeaa55791d91c4aea70f70def0c73700c9b07f051bb44230c3cb6a859aa88f5b19cef340ece42aea463254acc9e190125b1f6"] %>
email_provider_username: <%= ENV["Blabla"] %>
email_provider_password: <%= ENV["Blabla"] %>
domain_name: example.com
mailchimp_api_key: <%= ENV["96d57479cfasfafafa"] %>
mailchimp_list_id: <%= ENV["e3ettq"] %>
owner_email: <%= ENV["Blabla@ddd.ua"] %>
RAILS_ENV=production rake secret



.bash_profile

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session as a function

export SENDGRID_USERNAME="Blabla"
export SENDGRID_PASSWORD="Blabla"
export MAILCHIMP_API_KEY="96d57479cfasfafafa"
export MAILCHIMP_LIST_ID="e3ettq"
export OWNER_EMAIL="Blabla@ddd.ua"
export SECRET_KEY_BASE="a720feb188850db37612fad94b21e71fb869e9843c6b4da34803f65097b8f0cb30e1b46190ea0838d10dd9860bac3329937981787da4dd20827c95efcaa51ac5"

Can You please help me. I followed like 10 or more forums but still without result.
THANK YOU

Reply

If working in development, i.e on your local machine you don't need the secrets or other environment variables set within your bash_profile.

As the error states, you can set it within the config/secrets.yml file:

development:
secret_key_base: my-secret-key

The way environment variables work in the production environment would be...

You'd have this in your config/secrets.yml file:

production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

And in your bash_profile on your production server you'd have the line:

export SECRET_KEY_BASE="my-secret-key-here"

So, when rails reads the secrets.yml file you're basically saying "you can find my secret key in the environment variable SECRET_KEY_BASE"

Reply

Thank You for answer.

Still the same problem. So I decided to start this project from begining. I did only one diffrence. Previously I create new secret key base via command $ rails secret (I deleted the origin one). And now in the new project I used the origin one created with new rails app ($ rails new . ). And now it works. So probably isn't so easy just generate new key and replace the old one (I restart server and terminal).

Marek

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.