如何在配置/初始化程序中使用 YML 值
我正在努力将 Facebook 集成到我的应用程序中。为此,我使用 koala、devise 和omniauth。
对于考拉,我有
/config/facebook.yml
development:
app_id: 123123132123
secret_key: dasadsasd1231231
test:
app_id: 313131313
secret_key: das132asdads12132
production:
app_id: dasdsadsadsadsa
secret_key: adsdsa12das123fds21
然后也有omniauth:
/config/initalizers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 123123132123, 'dasadsasd1231231'
end
这里的问题是我在两个位置重复了相同的值。我怎样才能解决这个问题,以便 app_id 和 Secret_key 只存在于一个地方,并且一个文件引用另一个文件?
I'm working to integrate facebook in my app. To do that I'm using koala, devise, and omniauth.
For koala, I have
/config/facebook.yml
development:
app_id: 123123132123
secret_key: dasadsasd1231231
test:
app_id: 313131313
secret_key: das132asdads12132
production:
app_id: dasdsadsadsadsa
secret_key: adsdsa12das123fds21
I then also have with omniauth:
/config/initalizers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 123123132123, 'dasadsasd1231231'
end
Problem here is I have the same value repeated in both locations. How can I dry this up so that the app_id and secret_key only live in one place and one file references the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个很棒的 Railscast 可以做到这一点: http://railscasts.com/episodes/85-yaml-configuration-file
在
omniauth.rb
中,您可以添加以下行:然后您可以执行以下操作:
There is a great Railscast on doing this: http://railscasts.com/episodes/85-yaml-configuration-file
In
omniauth.rb
, you can add this line:Then you can do:
除了上述答案之外,您可能需要使用略有不同的代码来加载文件:
In addition to the above answer you might need to use slightly different code to load the file: