Reputation: 4406
I am adding Facebook authentication with omniauth to my application according to Ryan Bates screencast
There is a problem with the create function in the authentication controller. the create function should handle the facebook callback (which seems to be fine).
The error in the log file is:
NoMethodError (undefined method `authentications' for nil:NilClass)
The error refers to this line in the create function in the authentication controller:
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
What do you think is the problem?
Thanks,
Oded
Upvotes: 4
Views: 2483
Reputation: 755
I had the same problem too but it's solved. The reason this error is thrown is that the AuthenticationController’s create action expects there to be a currently logged-in user and tries to find or create a new authentication for that user. As we’re trying to authenticate without having first logged in with a user name and password the current_user variable will be nil.
Follow the link to solve the problem http://railscasts.com/episodes/236-omniauth-part-2?view=asciicast
Upvotes: 0
Reputation: 2751
The problem is that you are not logged in when you try to authenticate, thus the current_user is nil. Log in and then authenticate and you will be redirected to the authentications index page. That is the way that he did it in the railscast. In the next episode he addresses the user not being logged in.
Upvotes: 4
Reputation: 20675
Your current_user
is nil, so when you try to access authentications on a nil object you get the error message that you're seeing.
You need to fix your current_user
method.
Upvotes: 1