0

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).

Community
  • 1
  • 1
Lee Eather
  • 345
  • 3
  • 16

1 Answers1

1

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]
Breno Perucchi
  • 873
  • 7
  • 16
  • When I try and do require 'yaml' in rails console it returns a false value? The others I am not to sure what is happening there. – Lee Eather Aug 21 '16 at 03:05
  • 1
    Is ok about returns false. Show me the puts returns – Breno Perucchi Aug 21 '16 at 03:34
  • NameError: undefined local variable or method `yaml' for main:Object from (irb):1 .... then the list of gems that failed to initialize – Lee Eather Aug 21 '16 at 05:05
  • ok so now is giving me the results `=> {"development"=>{"app_id"=>abcdefg, "app_secret"=>"123456"}, "production"=>{"app_id"=>abcdefg, "app_secret"=>"123456"}}` – Lee Eather Aug 21 '16 at 11:34
  • I wish it did for some reason still getting the same response "the parameter app_id is required" I may have to try something else maybe the figaro gem, can you see whats wrong? – Lee Eather Aug 22 '16 at 04:01
  • sorry the penny dropped, i had had the app_id and app_secret still set as the 'actual' app id and secret so the FACEBOOK_CONFIG constant was not registering.Thanks for your help. – Lee Eather Aug 22 '16 at 08:21
  • 1
    No problem. Any time. – Breno Perucchi Aug 22 '16 at 13:56