← cd ../blog
local-env-something-for-rails-app.md skrdev
~December 12, 2021 · 1 min read

Local ENV['SOMETHING'] for Rails App

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) …

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. 
Original post ↗

// keep reading

dmitrii skr.

I build fast, reliable web products — from the data model to the last pixel.

More

© 2026 Dmitrii Skrylev. All rights reserved.

Built with SvelteKit · Lantana, TX · Remote