繁体   English   中英

使用Google OAuth2的故障Rails 3的AbstractController ActionNotFound

[英]AbstractController ActionNotFound for failure rails 3 using google oauth2

我在使用google登录时选择了帐户并点击输入后,即显示此错误,因此我正在使用google oauth2。

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

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

omn​​iauth的控制器

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

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

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

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

更好的方法是添加名称空间User,因为控制器位于“ app / controllers / users”中

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM