Rails Production - How to set Secret Key Base?

nvrpicurnose picture nvrpicurnose · Mar 21, 2015 · Viewed 37.1k times · Source

So I am trying to get my rails app to deploy in production mode, but I get the error: Missing secret_token and secret_key_base for 'production' environment, set these values in config/secrets.yml

My secrets.yml file is as expected:

development:
  secret_key_base: xxxxxxx

test:
  secret_key_base: xxxxxxx

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

But even after google and research, I have no idea what to do with the production secret key base. Most of the info out there assumes I have certain background knowledge, but the reality is that I'm a noob.

Can anyone explain to me how to set my secret key and get this to work in production mode?

Answer

Tarun Rathi picture Tarun Rathi · Dec 18, 2015

You can generate the key by using following commands

$ irb
>> require 'securerandom'
=> true
>> SecureRandom.hex(64)
=> "3fe397575565365108556c3e5549f139e8078a8ec8fd2675a83de96289b30550a266ac04488d7086322efbe573738e7b3ae005b2e3d9afd718aa337fa5e329cf"
>> exit