Using envvault with Ruby/Rails
Note: Please ensure that you have completed the previous steps
Prerequisites
- Ruby installed on your system
- envvault CLI tool installed
- An existing Ruby on Rails project
Usage
Running Your Application
To run your Rails application with environment variables from envvault:
$ envvault run --env=dev rails server
Caching Environment Variables
For better performance, you can cache your environment variables:
$ envvault run --env=dev -c -- rails server
Example Implementation
Here is how to set up a basic Rails application with envvault:
# config/application.rb
module YourApp
class Application < Rails::Application
# Your environment variables are automatically loaded
config.port = ENV['PORT'] || 3000
config.database_url = ENV['DB_URL']
end
end
# app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
render plain: 'Hello from envvault!'
end
end