Reputation: 9842
I have a rails app that connects to various APIs, and instead of putting my API keys directly in the Rails project, I'd like to make a separate file, secrets.rb, that contains global string variables for all of my API secret keys.
Where should I save this, and how can I make sure that these globals will be included where I need them in my project?
Upvotes: 0
Views: 357
Reputation: 353
I think better way is a create config.yml and add to gitignore.
# config/config.yml
development:
api_key = 'dev_key'
test:
api_key = 'test_key'
# config/initializers/app_config.rb
AppConfig = YAML.load_file(Rails.root.join('config', 'config.yml'))[Rails.env]
Upvotes: 0
Reputation: 11896
You could create an initializer with your API constants and add it to .gitignore
:
# config/initializers/secrets.rb
API_KEY = 'my_api_key'
API_SECRET_KEY = 'my_api_secret_key'
You could add them to config/environments/development.rb
as suggested by @engineersmnky in the comments, but you typically want to add development.rb
into version control.
Upvotes: 1