3
votes

I am running a Rails 4.2.3 application that runs in production when deployed and with environment variables set through Heroku. However, my development and test environments suddenly began failing with this error:

DEPRECATION WARNING: You didn't set `secret_key_base`. Read the upgrade documentation to learn more about this new config option. (called from service at /Users/Benjamin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138)

According to everything I've found on StackOverflow and elsewhere, this probably has something to do with my secrets.yml file:

development:
  secret_key_base: LONG-KEY

test:
  secret_key_base: LONG-KEY

I have tried resetting these keys with

rake secret
to no avail. I have other environment variables set in secrets.yml that are being correctly set, but when I run Rails.application.secrets.secret_key_base from console I keep getting nil.

Any help would be much appreciated.

2

2 Answers

1
votes

When you say you have tried resetting them with rake secret what do you mean? You copied and pasted the keys from the console into secrets.yml into the correct spots and saved? As long as both keys are in there, are at least 30 chars long (they would be 128 chars long in your case having u used rake secret) you should be all set. I assume your secrets.yml file is located in config/.

Also, the deprecation warning is a warning not an error. As long as the keys are in the secrets.yml you should not have to do anything else. Running rake secret and replacing the keys with new ones is unnecessary, as long as you have keys there (of at least 30 chars) it doesn't matter what the keys are.

Hope this helps. If you are still having difficulty, post the runtime error and hopefully it will provide more insight into what is wrong.

1
votes

This is not likely your problem, but I have spent hours on this issue, which was also giving me the same error message of 'secret_key_base' not being set for the production rails server start. I am running Rails ver. 4.2.5.1, Ruby ver. 2.3.0, WEBrick 1.3.1, with the development and production server running experimentally on a CentOS 6.6 Linux box. My error was a complete newbie thing.. I had followed the steps to configure a SECRET_BASE_KEY for production, and am using the secrets.yml file, with the environment var being used to set the key, as per Rails docs and other Stackoverflow reports. But I was starting my production server with:

bin/rails server --binding=0.0.0.0 -p 3000 -e=production

which is wrong. The short form "-e" parameter has no equals sign. But the error I got was because the code in the secrets.yml file was looking for something called "=production:", and the label is "production:". The correct expression to start the server in production mode is of course:

bin/rails server --binding=0.0.0.0 -p 3000 -e production

The other clue, was that the server was reporting "config.eager_load" was set to nil, when in fact it was configured to be set in the ../config/environments/production.rb file.

Hope this helps someone. I am a complete newbie at Rails+Ruby, but I finally have a testbed server running in a production mode, with the various config settings applied as expected.