无法从 Rails 3.1 初始化程序访问环境变量
我有一个如下所示的初始化程序文件:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '000000000000000', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
end
我的应用程序可以运行。
我不想对凭据进行硬编码,因此我将其更改为:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
end
我在 bash 中设置了相应的环境变量,然后重新启动了我的应用程序。
当我使用 Rails 控制台时,ENV['FACEBOOK_KEY'] 和 ENV['FACEBOOK_SECRET'] 输出正确的值。
但我的应用程序不再工作,在使用omniauth 时收到“缺少 client_id 参数”的响应。
{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException"
}
}
我很困惑。
这不是访问环境变量的正确方法吗?它在初始化程序中是否以另一种方式工作?
如何从初始化程序访问环境变量?
顺便说一句,我正在使用 Ubuntu 11.04。
谢谢
I have an initializer file that looks like this:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '000000000000000', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
end
And my app works.
I don't want to hardcode credentials so I changed it to:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
end
I set the corresponding environment variables in bash, and restarted my app.
When I use the rails console, ENV['FACEBOOK_KEY'] and ENV['FACEBOOK_SECRET'] output the correct values.
But my app does not work anymore, I get a response with "Missing client_id parameter" when using omniauth.
{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException"
}
}
I'm confused.
Isn't it the correct way to access environment variables ? Does it work another way in initializers ?
How can I access the environment variables from the initializer ?
BTW I'm using Ubuntu 11.04.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
位于块内的某些内容会覆盖 ENV 和 env。这是omniauth建议的方式:
https://github.com/intridea/omniauth/wiki/动态提供者
Something about being inside the block overrides ENV and env. This is the omniauth suggested way:
https://github.com/intridea/omniauth/wiki/Dynamic-Providers