AbstractController ActionNotFound for failure rails 3使用google oauth2

时间:2013-09-24 14:22:56

标签: ruby-on-rails ruby devise omniauth

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

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

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

omniauth控制器

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

1 个答案:

答案 0 :(得分:1)

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

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

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

或者更好的是,添加名称空间用户,因为控制器位于“app / controllers / users”

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController