我有我的班级用户:: OmniauthCallbacksController<设计:: OmniauthCallbacksController 我正在覆盖after_omniauth_failure_path_for方法:
protected
def after_omniauth_failure_path_for resource
'/report_failure'
end
但超级的是被召唤的那个。
我怀疑这是因为passthru解决方法:
devise_for :users do
get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
有人知道如何克服这个问题吗? 我正在使用Devise 2.0.4
这是日志文件报告:
Started GET "/users/auth/facebook/callback?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request." for 77.124.184.115 at 2012-04-19 11:34:46 +0000
Processing by Devise::OmniauthCallbacksController#failure as HTML
Parameters: {"error_reason"=>"user_denied", "error"=>"access_denied", "error_description"=>"The user denied your request."}
Redirected to http://myapp.com/users/sign_in
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
编辑:如果我删除了passthru重定向,那么它可以工作:
# def devise_for :users do
# get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
# end
谢谢
答案 0 :(得分:0)
您忘记添加:controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
devise_for路由配置的参数,没有它omniauth不知道在失败后重定向到哪个控制器。
答案 1 :(得分:0)
我在omniauth_callbacks
中正确设置了routes.rb
控制器,但是仍然无法覆盖failure
或after_omniauth_failure_path_for
方法。问题在于,在出现问题的用户模型之前,我还设计了一个具有空路径的用户模型:
devise_for :customer_users, path: ''
# [...]
devise_for :users, module: 'users' # using a module instead of controllers
这导致始终匹配this devise omniauth方法中的customer_user
映射。因此,故障由默认的Devise::OmniauthCallbacksController
处理:
Processing by Devise::OmniauthCallbacksController#failure as HTML
可以通过为customer_users
设置非空路径来解决此问题:
devise_for :customer_users, path: 'customer'
# or the default
devise_for :customer_users
我希望这有助于防止有人犯同样的错误。