0

I am trying to set the fb app id (used by omniauth) so that its global to devise initialiser and to the controllers.

MORE INFO

I need it in devise initialiser (config/initializer/devise.rb) so that I can set config.omniauth :facebook, fb_app_id, fb_app_secret

Attempted Solution

I tried adding this info into a yml file ( http://railscasts.com/episodes/85-yaml-configuration-file ), however, looks like the yml hash is set for the controllers, but I can not use it for the devise initialiser.

/home/ubuntu/myapp/config/initializers/devise.rb:215:in `block in <top (required)>': uninitialized constant APP_CONFIG (NameError)

Any ideas?

Karan
  • 14,824
  • 24
  • 91
  • 157

3 Answers3

5

For those who are interested, I ended up writing up the variables in config/environments/production.rb & config/environments/development.rb

You can set global variables by adding:

config.fb_app_id = 23839282 
config.fb_app_secret = aj32j32j4jk

(set the appropriate one in production.rb or development.rb)

These can then be used in initialisers, and also in my actual application's views, controllers, etc.

Rails.configuration.fb_app_id
Rails.configuration.fb_app_secret

Read the second answer in: How to define custom configuration variables in rails

Community
  • 1
  • 1
Karan
  • 14,824
  • 24
  • 91
  • 157
0

I do this by adding an initializer (called env.rb) that set up the various env vars I need (as ENV['FACEBOOK_APP_ID'], for instance).

ksol
  • 11,835
  • 5
  • 37
  • 64
  • interesting - however, these environment variables cannot distinguish whether I am on development or production mode ... – Karan Apr 30 '12 at 16:46
  • you could set them in your production server manually (eg. using `export FACEBOOK_APP_ID=...`, and in the initializer, instead of using `=`, you could use `||=` – ksol Apr 30 '12 at 16:58
  • hmm... is there any way of loading it through yml - im trying to get something similar to what is described in the railcast – Karan Apr 30 '12 at 17:02
0

I had a similar problem but I came to a different solution. I passed ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'] into CONFIG.OMNIAUTH from within devise.rb. Then I add the environment variable (~/.bash_profile) or heroku config:add FACEBOOK_APP_ID. This allows me to install to new environments and regenerate APPIDs without pushing new code.

michaelhawkins
  • 1,026
  • 8
  • 8