user2804881
user2804881

Reputation: 107

Rails 4.0.5 secret.yml configuration

So I'm trying to get my first ruby on rails app running and after running "rails s" for the first time, I get the following message when I navigate to localhost:3000:

Internal Server Error

You must set config.secret_key_base in your app's config.

I did some research and it looks like I need to configure my secrets.yml file but am unsure what it should look like. This is what my secrets.yml file looks like:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa



test:
  secret_key_base: fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa


# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

the development and test secret_key_base come from the key that's generated when I run "rake secret".

What am I supposed to put in the production secret_key_base (that's what I speculate is wrong)?

Edit: What is my config/initializers/secret_token.rb file supposed to look like? This is what I have for that:

Demoapp::Application.config.secret_key_base = fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa

SOLUTION: I had forgotten to put the generated key in quotes inside my config/initializers/secret_token.rb file. config/initializers/secret_token.rb now looks like this and works fine:

Demoapp::Application.config.secret_key_base = 'fe3ffe8d0308f92a4765f3ea02264cd24f1ddc9dd5a64aa601c61402c85e2de4d5fb74df8d66ef6d2a43dee34584dce87a51f83050d4d1d57320b5e846a6a8aa'

Upvotes: 2

Views: 1021

Answers (1)

vee
vee

Reputation: 38645

You're supposed to add an environment variable SECRET_KEY_BASE with value from a new rake secret command on the server that hosts this production environment. In secrets.yml, the production secret_key_base is assigned the value of this environment variable SECRET_KEY_BASE.

Please see Environment variable for information on the subject across different platforms.

Setting the environment variable satisfies the requirement, and you need not modify the secrets.yml file.

Upvotes: 1

Related Questions