rails get variable from .env code example
Example 1: rails call env file
#in the .ENV file:
SECRET_TOKEN=qoLsDGcc8YEdeFQ8xWbtiwafMJvjUXpH
#in your code
key = ENV['SECRET_TOKEN']
Example 2: ruby on rails set environment variables example
config.before_configuration do env_file = File.join(Rails.root, 'config', 'local_env.yml') YAML.load(File.open(env_file)).each do |key, value| ENV[key.to_s] = value end if File.exists?(env_file)end