5 ms·
Taylor Mock and I are the authors of the article. Here's why we wrote the article. And why we suggest an alternative to using the Unix shell to set local enviro
by DanielKehoe 14y ago
Taylor Mock and I are the authors of the article. Here's why we wrote the article. And why we suggest an alternative to using the Unix shell to set local environment variables.
The rails-stripe-membership-saas example application [1] from the RailsApps project has become very popular. I've been getting lots of requests for help stemming from problems setting local environment variables. Personally, I prefer to use the Unix shell to set local environment variables such as email account credentials and API keys. Always has worked for me. Apparently some people have trouble (perhaps complications with rvm or just plain ignorance). Anyway, telling newbies to school up is not a solution. So Taylor Mock came up with a trick to use Ruby to set local environment variables from a Rails application without involving the Unix shell.
It has some advantages. If the variables are set in the shell, the code just works. If the shell environment is a mess, the developer can use a local_env.yml file to set the environment variables.
There are several other valid and appropriate approaches (a .env file, a dotenv gem, etc). Also, there is a whole mini-industry of clever gems for setting constants and configuration variables in Rails. This is different. This is just intended for variables such as email account credentials and API keys that shouldn't be hardcoded.
I describe the motivations for the article in a RailsApps blog post [2].
[1] http://railsapps.github.com/rails-stripe-membership-saas http://railsapps.github.com/rails-stripe-membership-saas
[2] http://blog.railsapps.org/ http://blog.railsapps.org/
- deleted 14y ago[deleted]
- strife25 14y agoTotally agree on your thoughts with relying on env. variables - I hit the same issue with trying to write re-usable Chef code. Another pro tip w/r/t environment variables: NEVER rely on $PATH - that should be considered a global variable that any arbitrary piece of code in your process can modify at will since everyone knows about it. I know Jruby use to rely on this for their Ant integration and it was annoying as hell before it was fixed.