2013-02-11 72 views
0

如何定义Devise after_sign_in_path以重定向到页面用户,然后单击登录?我已经在application_controller中尝试了这一点:使用自定义会话控制器设计after_sign_in_path

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的自定义控制器。我究竟做错了什么?

+0

你能说出'if'语句正在执行哪个分支吗? – rossta 2013-02-11 14:04:55

回答

2

您不需要触摸after_sign_in_path_for(resource_or_scope),因为这是默认行为。

的返回路径存储在session["user_return_to"](如果用户是你的色器件的范围),以及由store_location! in FailureApp

设置此故障应用程序被称为每次监狱长验证失败:看warden config调用Delegator

有没有可能你绕过这些?

这种情况下,如果你warden-验证没有爆炸。通过故障应用程序监狱长仅保释金,如果你打电话warden.authenticate!,看到warden wiki这确实发生if you call devise's authenticate_user!

请确保您在使用的情况下在你的会话控制器like hereafter_sign_in_path_for为导向位置,你有一个自定义的。

+0

是否可以因为我的自定义my_sessions控制器而绕过它? – oFca 2013-02-15 00:22:09

+0

我更新了我的回答 – 2013-02-15 08:25:56

+1

你有没有成功? – 2013-02-18 12:51:46