I am following rails cast #85 here and the marked correct answer on stackoverflow here.
I am trying to use facebook "app_id" and "app_secret" to set as environment variables in rails.
my code is:
initializers/facebook.rb
FACEBOOK_CONFIG = YAML.load_file("#{::Rails.root}/config/facebook.yml")[::Rails.env]
config/facebook.yml
development:
app_id: abcdefg
app_secret: 123456
production:
app_id: abcdefg
app_secret: 123456
initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, FACEBOOK_CONFIG['abcdefg'], FACEBOOK_CONFIG['123456'], {:client_options => {:ssl => {:ca_file => Rails.root.join("cacert.pem").to_s}}}
end
When I set the environment variables in front of the app_id and app_secret ie FACEBOOK_CONFIG when I try login through facebook it returns a "app_id parameter is required" message. So this way is not working. I am wondering if there is some code missing or someone can see something I am doing wrong the environment variables are not being processed through facebook (where they were before without any ENV variables).
in your rails console
try it
edit
require 'yaml'
yaml = YAML.load_file(File.expand_path("#{Rails.root}/config/facebook.yml"))
puts yaml
*edit 2 *
FACEBOOK_CONFIG = YAML.load_file("#{::Rails.root}/config/facebook.yml")[::Rails.env]
change to:
FACEBOOK_CONFIG = YAML.load_file(File.expand_path("#{Rails.root}/config/facebook.yml"))[::Rails.env]