问题
I am following the below tutorial of omniauth-facebook for configuring the authentication method from facebook in my rails application:
http://railscasts.com/episodes/360-facebook-authentication
Everything is running fine but after callback I'm getting the following error:
undefined method `from_omniauth' for #<Class:0x007ff05a58de30>
and the code snippet:
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"]) #Highligted line as red
session[:user_id] = user.id
redirect_to root_url
end
Following is my session_controller file:
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end
Model (user.rb)
class User < ActiveRecord::Base
def self.from_omniauthsk(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
Gem I'm using is
gem 'omniauth-facebook'
回答1:
you just have a typo:
from_omniauthsk
should be
from_omniauth
来源:https://stackoverflow.com/questions/36114675/authentication-failure-omniauth