ruby on rails - Trying to hide some Twitter API credentials in a Yaml file, getting uninitialized constant EnvironmentVariables::Application::YAML -
i have initializer environment_variables.rb
:
module environmentvariables class application < rails::application config.before_configuration env_file = rails.root.join("config", 'environment_variables.yml').to_s if file.exists?(env_file) yaml.load_file(env_file)[rails.env].each |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
which i've checked finding file called environment_variables.yml
in config:
test: twitter_consumer_key: "" twitter_consumer_secret: "" twitter_access_token: "" twitter_access_token_secret: "" development: twitter_consumer_key: "" twitter_consumer_secret: "" twitter_access_token: "" twitter_access_token_secret: "" production: twitter_consumer_key: "" twitter_consumer_secret: "" twitter_access_token: "" twitter_access_token_secret: ""
however error when trying run code:
class twitterapi def client @client ||= twitter.rest.client.new |config| config.twitter_consumer_key = env['twitter_consumer_key'] config.twitter_consumer_secret = env['twitter_consumer_secret'] config.twitter_access_token = env['twitter_access_token'] config.twitter_access_token_secret = env['twitter_access_token_secret'] end end end
by making call in spec puts twitterapi.new.client
test it. error looks this:
/users/nathanielmots/documents/development/takestock/stock/config/initializers/environment_variables.rb:7:in `block in <class:application>': uninitialized constant environmentvariables::application::yaml (nameerror)
any suggestions problem? help.
uninitialized constant environmentvariables::application::yaml
means, can't find definition of yaml
. so, need require in file using yaml
.
in environment_variables.rb
, require yaml
:
require 'yaml'
this should fix issue.
Comments
Post a Comment