0

当我使用谷歌登录时,我正在使用谷歌 oauth2,在我选择我的帐户并点击输入后出现此错误。

AbstractController::ActionNotFound at /users/auth/google_oauth2/callback
The action 'failure' could not be found for OmniauthCallbacksController

我好难过!我做错了什么?

全域认证控制器

class OmniauthCallbacksController < ApplicationController
    def google_oauth2
        auth_details = request.env["omniauth.auth"]
        if auth_details.info['email'].split("@")[1] == "company.net"
            user = User.from_omniauth(request.env["omniauth.auth"])
            if user.persisted?
                flash.notice = "Signed in Through Google!"
                sign_in_and_redirect user
            else
                session["devise.user_attributes"] = user.attributes
                flash.notice = "Please provide a password"
                redirect_to new_user_registration_url
            end
        else
            render :text => "Sorry this site is for company employees only"
        end
    end
end

在 intializers/devise.rb 我有 config.omniauth 要求

痕迹

the error show this process actionpack-3.2.13/lib/abstract_controller/base.rb

这是它突出显示的线

unless action_name = method_for_action(action_name)
    raise ActionNotFound, "The action" '#{action}' could not be found for #{self.class.name}"
end
4

1 回答 1

1

我懂了。该failure方法应该属于 Devise 的控制器。您没有从 Devise 继承控制器,而是从 ApplicationController 继承,因此无法找到此方法。

由于您正在基于 Devise 实现 Omniauth,因此该控制器需要从 Devise 继承。

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

或者更好的是,添加一个命名空间用户,因为控制器在 'app/controllers/users'

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
于 2013-09-24T15:29:42.480 回答