How to use YML values in a config/initializer

偶尔善良 提交于 2019-12-04 04:36:57

There is a great Railscast on doing this: http://railscasts.com/episodes/85-yaml-configuration-file

In omniauth.rb, you can add this line:

FACEBOOK_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/facebook.yml")[RAILS_ENV]

Then you can do:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, FACEBOOK_CONFIG['app_id'], FACEBOOK_CONFIG['secret_key']
end

In addition to the above answer you might need to use slightly different code to load the file:

FACEBOOK_CONFIG = YAML.load_file(Rails.root.join("config","facebook.yml"))[Rails.env]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!