omniauth.auth 上的 nil 方法错误


    def create
   5      debugger
   6      auth=request.env["omniauth.auth"]
=> 7      user=Moviegoer.find_by_provider_and_uid(auth["provider"],auth["uid"]) ||
   8        Moviegoer.create_with_omniauth(auth)
   9      session[:user_id] = user.id
   10      redirect_to movies_path

上面的代码来自控制器操作(创建) - 我在调试器打开的情况下运行;我正在获得身份验证变量的"零"值 - 我在 gem 文件中有全身份验证并安装了捆绑包......仍然无法正确执行上述语句...我在这里错过了什么吗...?------

我尝试了几件事并前进了几步 - 但仍然卡在一个错误上

在 2013-12-28 17:38:26 -0800 为 127.0.0.1 启动 GET "/auth/twitter"

超时::错误(执行已过期):

应用程序控制器中的代码是:

class ApplicationController < ActionController::Base
  before_filter :set_current_user
  protected # prevents method from being invoked by a route
  def set_current_user
    debugger
    # we exploit the fact that find_by_id(nil) returns nil
    @current_user ||= Moviegoer.find_by_id(session[:user_id])
    redirect_to '/auth/twitter' and return unless @current_user
  end
end

我相信代码在语句redirect_to超时...

您应该将 oauth 回调映射到您的创建操作。

# config/routes.rb
match '/auth/:provider/callback' => 'authentications#create'

最新更新