Karan
Karan

Reputation: 15104

Rails: Where to define facebook app id so that it is available to the devise initializer and the controllers.

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?

Upvotes: 0

Views: 2221

Answers (3)

michaelhawkins
michaelhawkins

Reputation: 1066

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.

Upvotes: 0

Karan
Karan

Reputation: 15104

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

Upvotes: 5

ksol
ksol

Reputation: 12255

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

Upvotes: 0

Related Questions