Where should I store the api key in rails3?

What is the best practice for storing / retrieving API keys in rails3?

Should I create my own yaml application and access it through it? If so, how?

Sorry for the noob question ...

+6
ruby-on-rails-3 app-config api-key
source share
1 answer

I use the settingslogic plugin for such things. Very easy to use.

Add logic settings to your Gemfile and bundle install :

 gem 'settingslogic' 

Create a directory for your settings and place your log there:

 /my_app/config/settings/my_settings.yml 

You can enable default settings and environment settings. The file is as follows:

 defaults: &defaults api_key: abc123 development: <<: *defaults test: <<: *defaults production: <<: *defaults 

Add this file: app/models/my_settings.rb , run your application, and you're good to go

 class MySettings < Settingslogic source "#{Rails.root}/config/settings/my_settings.yml" namespace Rails.env end 

Now you can use these settings from anywhere in the application, for example:

 MySettings.api_key 
+10
source share

All Articles