

#Deleted keybase app kept chat images code
The reason for the Rails team to introduce this is beyond the scope of this answer but the TL DR is that secret_token.rb conflates configuration and code as well as being a security risk since the token is checked into source control history and the only system that needs to know the production secret token is the production infrastructure. While you can use initializers like the other answers, the conventional Rails 4.1+ way is to use the config/secrets.yml. When you close your shell and login again to the production server you will have this environment variable set and ready to use it.Īnd that's it! I hope this mini-guide helps you solve this error.ĭisclaimer: I'm not a Linux or Rails guru, so if you find something wrong or any error I will be glad to fix it. Finally with all the configuration done you should be able to deploy without problems your Rails application with Unicorn or some other tool.

When you execute this command, if everything went ok, it will show you the GENERATED_CODE from before. You can verify that our environment variable is properly set in Linux with this command: $ printenv | grep SECRET_KEY_BASE Having written the code, save the changes and close the file using Esc again and " :x" and Enter to save and exit. Then we go to the bottom of the file using Shift+ G again and write the environment variable with our GENERATED_CODE using i again, and be sure add a new line at the end of the file: $ export SECRET_KEY_BASE=GENERATED_CODE If you found these two files in your directory ~/.bash_profile and ~/.profile you only will have to write in the first one ~/.bash_profile, because Linux will read only this one and the other will be ignored. These files are in order of importance, which means that if you have the first file, then you wouldn't need to edit the others. Save the changes and close the file using Esc and then " :x" and Enter for save and exit in vi.īut if you login as normal user, let's call it " example_user" for this gist, you will need to find one of these other files: $ vi ~/.bash_profile Be sure to be in a new line at the end of the file: $ export SECRET_KEY_BASE=GENERATED_CODE Write your environment variable with the GENERATED_CODE, pressing i to insert in vi. Go to the bottom of the file using Shift+ G (capital "G") in vi. If you login as the root user, find this file and edit it: $ vi /etc/profile Copy that, which we will refer to that code as GENERATED_CODE. This returns a large string with letters and numbers. In the terminal of your production server execute: $ RAILS_ENV=production rake secret In order to solve this error you should follow these steps to create an environment variable for Linux (in my case Ubuntu) in your production server: This means that Rails recommends you to use an environment variable for the secret_key_base in your production server.

# instead read values from the environment. I was using Rails 4.1 with Unicorn v4.8.2 and when I tried to deploy my application it didn't start properly and in the unicorn.log file I found this error message: app error: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml` (RuntimeError)Īfter some research I found out that Rails 4.1 changed the way to manage the secret_key, so if you read the secrets.yml file located at exampleRailsProject/config/secrets.yml you'll find something like this: # Do not keep production secrets in the repository, I had the same problem and solved it by creating an environment variable to be loaded every time I logged in to the production server, and made a mini-guide of the steps to configure it:
