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: 2aa34dfb69c3749dcd646a0a4239a0 72
production:
TWITTER_KEY: cFXhhlfWanscuTkldGkM5GVLC
TWITTER_SECRET: 5k3ysJVPfEEgQMzaZ6aN7QqOtfIbUx OUKIJVvTf9kMcdqZLjEH
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']
development:
DEV_TWITTER_KEY: AQ01uxmLsGnCU1SpkuwrwPc9l
DEV_TWITTER_SECRET: srSrs9fc1zDy6enD1zsHE1zdyiMGMn
DEV_FACEBOOK_KEY: '1374702796089833'
DEV_FACEBOOK_SECRET: 2aa34dfb69c3749dcd646a0a4239a0
production:
TWITTER_KEY: cFXhhlfWanscuTkldGkM5GVLC
TWITTER_SECRET: 5k3ysJVPfEEgQMzaZ6aN7QqOtfIbUx
config/initializer/
module EnvironmentVariables
class Application < Rails::Application
config.before_configuration do
env_file = Rails.root.join("config", 'environment_variables.yml').
if File.exists?(env_file)
YAML.load_file(env_file)[
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
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
Comments
Post a Comment