使用OmniAuth和Devise RoR 5进行记录

时间:2017-09-10 20:21:58

标签: ruby-on-rails facebook devise omniauth omniauth-facebook

我正在关注此处的文档LINK

这是Users::OmniAuthCallbacksController facebook方法:

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?
        logger.debug "YES"
        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
        logger.debug "No"
        session["devise.facebook_data"] = request.env["omniauth.auth"]
    end
end

这是' application.html.erb'的一部分。图

<h1><%=user_signed_in? %></h1>

如果我尝试使用Facebook登录,则会在此users表格中为该用户创建新行,但它有效,但我看到user_signed_in?false。 我需要做些什么来验证Devise和OmniAuth?

0 个答案:

没有答案