我正在按照下面的 omniauth-facebook 教程,在我的rails应用程序中从facebook配置身份验证方法:
http://railscasts.com/episodes/360-facebook-authentication
一切正常但在回调后我收到以下错误:
undefined method `from_omniauth' for #<Class:0x007ff05a58de30>
和代码段:
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
以下是我的session_controller文件:
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
模型(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 'omniauth-facebook'
答案 0 :(得分:1)
from_omniauthsk
应该是
from_omniauth