Ruby on rails 使用facebook get设计gem登录”;您已登录。”;在登录或注册之后
我已使用以下gems登录/注册我的应用程序Ruby on rails 使用facebook get设计gem登录”;您已登录。”;在登录或注册之后,ruby-on-rails,facebook,devise,Ruby On Rails,Facebook,Devise,我已使用以下gems登录/注册我的应用程序 # Devise is a flexible authentication solution for Rails based on Warden. It: gem 'devise' #using omniauth gem 'omniauth' #facebook authentication using omniauth gem 'omniauth-facebook' 但在用户登录或注册后,我总是会收到flash: 您已登录 这是我的用户模型: cl
# Devise is a flexible authentication solution for Rails based on Warden. It:
gem 'devise'
#using omniauth
gem 'omniauth'
#facebook authentication using omniauth
gem 'omniauth-facebook'
但在用户登录或注册后,我总是会收到flash:
您已登录
这是我的用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.name = auth.info.name # assuming the user model has a name
user.image = auth.info.image # assuming the user model has an image
end
end
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
end
class用户[:facebook]
定义自授权(授权)
其中(provider:auth.provider,uid:auth.uid)。首先|
user.email=auth.info.email
user.password=design.friendly_令牌[0,20]
user.name=auth.info.name#假设用户模型有名称
user.image=auth.info.image#假设用户模型具有图像
结束
结束
定义self.new_与_会话(参数,会话)
super.tap do| user|
如果数据=会话[“designe.facebook_数据”]&会话[“designe.facebook_数据”][“额外”][“原始信息”]
user.email=data[“email”]如果user.email.blank?
结束
结束
结束
结束
我的用户控制器:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
class Users::OmniAuthCallbackController:authentication#如果未激活@user,将引发此错误
如果是导航格式,设置flash消息(:notice,:success,:kind=>“Facebook”)?
其他的
会话[“designe.facebook_data”]=request.env[“omniauth.auth”]
将\重定向到新\用户\注册\ url
结束
结束
结束
有什么想法或建议吗?我也有同样的问题。解决方案是在方法的路径中签名后更改
。例如,在ApplicationController
中:
在(资源)的路径中签名后定义
超级资源
结束
尝试删除数据库中的所有用户,然后再试一次。@RailsOuter我试过了,但出现了相同的错误我得到了相同的错误