从omniauth哈希中提取电子邮件以验证用户模型
我正在使用omniauth并设计让用户使用他们的facebook帐户登录,一切正常,但是当我尝试从哈希中提取他们的电子邮件时,我收到此错误:
NoMethodError in AuthenticationsController#create
undefined method `id' for "/":String
这是错误的完整日志:http://pastie.org/1698569
错误消失了,刷新后我就可以正常登录了!
编辑:事实证明,它在我的身份验证控制器中的第 22 行
sign_in_and_redirect_to(:user, root_path)
出于某种原因,运行此方法后我无法登录 :user
def apply_facebook(omniauth)
if (extra = omniauth['extra']['user_hash'] rescue false)
self.email = (extra['email'] rescue '')
end
end
但是,如果我不运行该方法,那么它可以登录并重定向到就好
这是我的控制器/模型http://pastie.org/1698453
非常感谢任何帮助
I'm using omniauth and devise to log users in with their facebook acounts, everything works however when I try to pull their email out of the hash I get this error:
NoMethodError in AuthenticationsController#create
undefined method `id' for "/":String
Here's the full log of the error : http://pastie.org/1698569
The error goes away and it lets me log in just fine after I refresh!
EDIT: It turns out that its line 22 in my authentications controller
sign_in_and_redirect_to(:user, root_path)
For some reason after running this method I can't sign_in the :user
def apply_facebook(omniauth)
if (extra = omniauth['extra']['user_hash'] rescue false)
self.email = (extra['email'] rescue '')
end
end
However, if I don't run that method, then it can sign_in_and_redirect_to just fine
Here's my controllers/model http://pastie.org/1698453
Really appreciate any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
root_path
作为sign_in_and_redirect
的第二个参数。以下是您可以使用它的一些可用方法:由于您的第二个参数既不是资源也不是选项(它是一个字符串),因此您会收到错误。您需要将其更改为:
如果您想自定义返回路径以强制其在登录后转到不同的 URL,您可以在 ApplicationController 中执行以下操作:
You can't use
root_path
as the second parameter forsign_in_and_redirect
. Here are some available ways you can use it:Since your second parameter isn't either a resource or options (it's a string), you're getting an error. You need to change it to:
If you want to customize the return path to force it to go to a different URL after sign-in, you can do something like this in your ApplicationController: