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
Then create a file in config/initializers folder , for example load_keys.rb and paste the following code inside that
load_keys.rb
Now you can use these inside your 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
Post a Comment