Is it still considered a best practice to load some configuration parameters inside environment.rb with yaml files within the /config directory? It seems like a pretty good way to do this, but if there was a better way, it'd be good to know about it. I've tried to find articles about loading configuration settings in Rails / YAML but most of the articles don't go past 2009. Makes me feel like there came a better (or new standard) way to do this. Thanks!
2 Answers
I've been using this gem for that purpose recently:
- SettingsLogic: https://github.com/binarylogic/settingslogic
Basically, you create a /config/application.yml
file that looks something like this:
defaults: &defaults
api:
johns_api_co:
api_key: my_key
secret: shh!!!
other_setting:
this: "is a config setting"
that: "and another thing"
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
There are so many ways to do this, but this works well and is pretty straightforward.
Heroku recommends storing config in your system environment vars (.env file on your local box) and use it with foreman gem. https://devcenter.heroku.com/articles/config-vars
One advantage is that it hides all your credentials from your code repo, which is great when you want to make it publicly available.