ruby on rails - Using Figaro and Secrets.yml to Manage Env Variables -


i have rails 4.1 app , i'm trying organize env variables. of right have secrets.yml file in config/ folder. installed figaro gem. goal have env variables in application.yml (not checked git) file , use secrets.yml (checked git) file map variables appliation.yml application. when print files using rails.application.secrets shows hashes this:

:salesforce_username=>"env['salesforce_username']" 

none of external services working env variables setup. when view traces, env['account_id'] being passed through in requests this:

v2/accounts/env['account_id']/envelopes 

in addition, cannot access env variables using rails.application.secrets.account_id in app.

secrets.yml

development:   account_id: <%= env['account_id'] %> 

aplication.yml

development:   account_id: "123456" 

application.rb

# preload tokens in application.yml local env config = yaml.load(file.read(file.expand_path('../application.yml', __file__))) config.merge! config.fetch(rails.env, {}) config.each |key, value|   env[key] = value.to_s unless value.kind_of? hash end 

the gem provides generator:

$ rails generate figaro:install 

the generator creates config/application.yml file , modifies .gitignore file prevent file being checked git repository.

you can add environment variables key/value pairs config/application.yml:

gmail_username: your_username 

the environment variables available anywhere in application env variables:

env["gmail_username"] 

this gives convenience of using same variables in code whether set unix shell or figaro gem’s config/application.yml. variables in config/application.yml file override environment variables set in unix shell.

in tests or other situations env variables might not appropriate, can access configuration values figaro method calls:

figaro.env.gmail_username 

use syntax setting different credentials in development, test, or production environments:

hello: world development:   hello: developers production:   hello: users 

in case, env["hello"] produce “developers” in development, “users” in production , “world” otherwise.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -