5

I am trying to go to my localhost and I keep getting the following error in my browser:

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

I have looked around and people say that you have to rake the secret key and then put it into config/initializers/secret_token.rb but I don't have a secret_token.rb file in my folder. I am running ruby version ruby 2.1.2p9 and rails version Rails 4.0.8 I am following the tutorial at railstutorial.org if that helps on 2.2

infused
  • 24,000
  • 13
  • 68
  • 78
Max Gee
  • 117
  • 1
  • 3
  • 9
  • Did you run `rake secret` in your console? – spickermann Aug 28 '14 at 02:55
  • possible duplicate of [DEPRECATION WARNING: You didn't set config.secret\_key\_base](http://stackoverflow.com/questions/22268669/deprecation-warning-you-didnt-set-config-secret-key-base) – Brad Werth Aug 28 '14 at 05:19

2 Answers2

18

Run rake secret to generate a new token.

Now create a new file config/initializers/secret_token.rb and add the following:

MyApp::Application.config.secret_key_base = '<token>'

Replace <token> with the one you just generated and replace MyApp with the actual module name of your app. You can find the module name of your app at the top of config/environments/development.rb

infused
  • 24,000
  • 13
  • 68
  • 78
1

Rails-5

In rails-5, create config/initializers/secret_token.rb

Add Rails.application.config.secret_key_base= 'secret_token'

where 'secret_token' = rake:secret

Restart the server