Local ENV['SOMETHING'] for Rails App

Hash tags: Local Environments Ruby on Rails Config Vars Secret File Location

The way I like to keep my local environment in a rails app.

You know sometimes we need to keep our config variables locally and the best way(at least to me) is the following:
1. Create YAML file with our local variables in config/local_env.yml

local_env.yml example

2. Add following to config/application.rb
    ##
    # Loads local env.
    #
    config.before_configuration do
      env_file = File.join(Rails.root, 'config', 'local_env.yml')
      YAML.load(File.open(env_file)).each do |key, value|
        ENV[key.to_s] = value
      end if File.exists?(env_file)
    end
3. Now you can call you local variables from any place in your application like the following:
ENV["PAYPAL_CLIEN_ID"]

**IMPORTANT: Make sure not to share local_env.yml on any online repositories for security reasons. 

PROJECTS


MORE BLOGS