Using Dotenv in Rails for Environment Variables
Automatically Installing Dotenv with Prelang
Sign up for Prelang to use this feature.
Installation
Prelang automates the process of installing Dotenv, an environment variable management gem for Ruby on Rails. This guide will explain how to install Dotenv and use it after your application generates.
- Find and add the Environment Variables feature
- Generate your application
This will add and configure the Dotenv Rails gem.
After Generation
Once you have your application up and running locally on your development environment, make a new file in your application's directory named .env
. Here, you can put sensitive environment variables as so:
FACEBOOK_SECRET_ID=123123123123123
SENDGRID_SECRET_KEY=234234234234234
Your environment variables will now be accessible from anywhere in your Rails application. Use them with ENV
like this:
ENV["FACEBOOK_SECRET_ID"]
Usually, these are use in initializers at config/initializers/
.
Automatic Rails Development Tools