As our RailsApps applications grow more popular, help requests are growing more frequent. Particularly with the release of the rails-stripe-membership-saas application, I’ve seen people having trouble with setting Unix environment variables. Granted, if you’re doing development with Rails, you really should be able to sort out your own problems with Unix environment variables. But telling newbies to school up is not really a solution. And sometimes the problems stem from rvm or other local shell complexities. Taylor Mock saw the problem and stepped up with solutions on two fronts. First, test suites to identify if the API keys required by the application are set properly; and second, a clever solution to set local environment variables through Rails, rather than the Unix shell.
Taylor Mock’s implementation takes advantage of Ruby’s ability to set environment variables as well as read them. We create a file named config/local_env.example.yml and then add some code to the Rails config/application.rb file to read key/value pairs from a YAML structure and set environment variables that can be used elsewhere in the Rails application. The result? A bulletproof way to set environment variables without the Unix shell.
For more about the solution, see the article Rails Environment Variables.
Special thanks to Taylor Mock this week. He’s making significant contributions to the RailsApps project with a combination of intelligence and dedication that’s overcoming obstacles and moving the project forward.