使用自定义会话控制器设计after_sign_in_path
如何定义设计post_sign_in_path以重定向到页面用户是在点击登录之前? 我在application_controller中试过这个:
13 def after_sign_in_path_for(resource_or_scope) 14 sign_in_url = url_for(:action => 'new', :controller => 'my_sessions', :only_path => false, :protocol => 'http') 15 if request.referer == sign_in_url 16 super 17 else 18 stored_location_for(resource_or_scope) || request.referer || root_path 19 end 20 end
有了这个,我只被重定向到root_path。 值得一提的是,我有Sessions callse MySessionsController的自定义控制器。 我究竟做错了什么?
您不需要触摸after_sign_in_path_for(resource_or_scope)
因为这是默认行为。
返回路径存储在session["user_return_to"]
(如果用户是您的设计范围),并由store_location!
设置store_location!
在FailureApp
每次warden身份validation失败时都会调用此失败应用程序:请参阅warden config调用Delegator
。
你有可能以某种方式绕过其中一些吗?
如果你在没有爆炸的情况下进行warden-authenticate就会发生这种情况。 如果你打电话给warden.authenticate!
warden只能通过失败应用程序warden.authenticate!
, 如果你打电话给devise的authenticate_user!
,请参见warden wiki authenticate_user!
确保在会话控制器中使用after_sign_in_path_for
作为重定向位置,如果您有自定义位置。