Docs

Rails

Encrypt a .env file in Rails with the Dotenvx gem, commit it safely, and load its secrets at runtime.

1. Install

Add the Dotenvx Rails gem.
# Gemfile
gem "dotenvx-rails"
Install it, and get the CLI to encrypt files.
$ bundle install
$ curl -sfS https://dotenvx.sh | sh

2. Encrypt

Encrypt your .env file.

$ dotenvx encrypt

3. Inject

Your encrypted secrets are automatically loaded. Use them anywhere.
class HomeController < ApplicationController
  def index
    render plain: "HELLO: #{ENV['HELLO']}"
  end
end