开发者

pulling email from omniauth hash to validate user model

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


You can't use root_path as the second parameter for sign_in_and_redirect . Here are some available ways you can use it:

sign_in_and_redirect :user, @user                      # sign_in(scope, resource)
sign_in_and_redirect @user                             # sign_in(resource)
sign_in_and_redirect @user, :event => :authentication  # sign_in(resource, options)
sign_in_and_redirect @user, :bypass => true            # sign_in(resource, options)

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:

sign_in_and_redirect(:user, user) # based on your pastie

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:

def after_sign_in_path_for(resource)
  "/go/to/this/path"
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜