Thursday, 14 May 2015

Setting Environment Variables with Figaro

You might have read another post from me which talks about setting up environment variables in which we implemented our own solution for assigning the env variables. Even thouh it was a pretty neat solution, the problem I faced was, I had to restart the rails server every time I made changes to the yaml file.

For a quick recap, you may want to use environment variables to store your secret credentials so that when you check your source code to a public repository, let's say github, your credentials aren't made public.

Meet Figaro, a gem which neatly does the job for you. First you'll need to add this line to your Gemfile and then run bundle update.

gem "figaro"

All you need to do now is run this on terminal

$ figaro install

This will create a config/application.yml file and also add it to .gitignore. Now you can just open up the application.yml file and set your environment variables. If you have to set value for ENV['MY_SECRET_IDENTITY'], in the file you will write

MY_SECRET_IDENTITY: 'Batman'

That's all for today. Happy Coding!

No comments:

Post a Comment