Skip to content

Instantly share code, notes, and snippets.

@sj26
Last active September 27, 2018 09:59
Show Gist options
  • Save sj26/354d2e4923a0b3a4370f to your computer and use it in GitHub Desktop.
Save sj26/354d2e4923a0b3a4370f to your computer and use it in GitHub Desktop.
Use dotenv with unicorn (put in config/boot.rb, thanks @keithpitt)
require "dotenv"
dotenv_root = File.expand_path("../../", __FILE__)
dotenv_env = ENV.fetch("RAILS_ENV", ENV.fetch("RACK_ENV", "development"))
dotenv_files = ["#{dotenv_root}/.env.#{dotenv_env}", "#{dotenv_root}/.env"]
if ENV.include? "DOTENV_LOADED"
ENV["DOTENV_LOADED"].split(":").each do |key|
ENV.delete(key)
end
end
dotenv_loaded = Dotenv.load(*dotenv_files)
ENV["DOTENV_LOADED"] = dotenv_loaded.keys.join(":")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment