Dotenv

Public
Shim to load environment variables from .env into ENV in development.
Icons/chart bar
Used 26 times
Created by
E Emanuele Bonanno

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/XnJsl0"
Template Source

Review the code before running this template on your machine.

def do_bundle
  Bundler.with_unbundled_env { run "bundle install" }
end

inject_into_file 'Gemfile', after: 'group :development, :test do' do
<<-RUBY
  gem "dotenv-rails"
RUBY
end

inject_into_file "config/application.rb", "require 'dotenv'"
inject_into_file "config/application.rb", "Dotenv.load if Rails.env.local?", after: "Bundler.require(*Rails.groups)\n"
inject_into_file ".gitignore", ".env"
file ".env", <<-CODE
CODE

do_bundle
Comments

Sign up or Login to leave a comment.