create environment variables files in rails

config/environment_variables.yml:-
development:
  DEV_TWITTER_KEY: AQ01uxmLsGnCU1SpkuwrwPc9l
  DEV_TWITTER_SECRET: srSrs9fc1zDy6enD1zsHE1zdyiMGMn
fp8yYePjMx8CmemVNYO3
  DEV_FACEBOOK_KEY: '1374702796089833'
  DEV_FACEBOOK_SECRET: 2aa34dfb69c3749dcd646a0a4239a072

production:

  TWITTER_KEY: cFXhhlfWanscuTkldGkM5GVLC
  TWITTER_SECRET: 5k3ysJVPfEEgQMzaZ6aN7QqOtfIbUxOUKIJVvTf9kMcdqZLjEH

Load environment variables file:-

config/initializer/
environment_variables.rb:-

module EnvironmentVariables
  class Application < Rails::Application
    config.before_configuration do
      env_file = Rails.root.join("config", 'environment_variables.yml').to_s

      if File.exists?(env_file)
        YAML.load_file(env_file)[Rails.env].each do |key, value|
          ENV[key.to_s] = value
        end # end YAML.load_file
      end # end if File.exists?
    end # end config.before_configuration
  end # end class
end # end module


Now we can use this like as :-
 provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']

Comments

Popular Posts

How to pass hash in Postman

nginx: unrecognized service

Bootstrap Select Picker append add new item if search not exist

Reading Excel Sheets using "Roo" gem in ruby on rails

Add CORS to Nginx on AWS Elastic Beanstalk

Enable gzip compression on Elastic Beanstalk with nginx

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Get video duration by URL in Ruby on Rails

site-enables nginx setting in ruby in rails