Best Way to Define API keys for Rails application

First Create a YML file inside the config folder of the application


your_file_name.yml
development: 
api_key: "your api key"
secret_key: "your secret key" 


Then create a file in config/initializers folder , for example load_keys.rb and paste the following code inside that
load_keys.rb
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/your_file_name.yml")[RAILS_ENV]

Now you can use these inside your application
APP_CONFIG['api_key']
APP_CONFIG['secret_key']

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails