Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
Environment Variables (Environment Variables) are configuration settings that are stored at the operating system level (for example, used by Ruby on Rails applications during runtime). They allow you to manage sensitive (confidential) information, such as database credentials or API keys, as well as configure the behavior of the application in different deployment environments, such as development, testing, and production.
What types of information can be stored in Environment Variables?
Environment Variables can store a variety of information, including database connection data, API keys, secret tokens, local development environment settings, and more.
How to access Environment Variables in a Ruby on Rails application?
In Ruby on Rails applications, access to Environment Variables can be obtained using the special object ENV, which provides access to all environment variables stored in the operating system.
Example of using Environment Variables
Imagine we have an application that uses an API key to interact with a third-party service. Instead of hardcoding the API key directly in the code, we can store it as an Environment Variable.
For example:
# Code in Ruby on Rails application to get the API key from Environment Variable api_key = ENV['API_KEY']
Thus, we can store confidential information, such as API keys, in Environment Variables, making our application more secure and flexible in different deployment environments.
The main rule is not to commit keys to a Git repository. Use Env variables instead.
This post doesn't have any additions from the author yet.