用Devise登录后重定向 [英] Redirect after sign in with Devise

查看:192
本文介绍了用Devise登录后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在使用Devise登录后将用户重定向到不同的页面(基于角色)?它只是重定向到根:to => ...在routes.rb中定义的页面

Is it possible to redirect users to different pages (based on role) after signing in with Devise? It only seems to redirect to the root :to => ... page defined in routes.rb

谢谢!

推荐答案

默认情况下,Devise在动作后会路由到root。有一篇关于在Devise Wiki上重写这些操作的好文章, https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in

By default Devise does route to root after it's actions. There is a nice article about overriding these actions on the Devise Wiki, https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in

或者您可以通过将 stored_locations_for(resource)设置为nil,然后再进行不同的重定向对于每个动作,即: after_sign_up_path(resource) after_sign_in_path(resource)等等。

Or you can go even farther by setting stored_locations_for(resource) to nil, and then have different redirects for each action, ie: after_sign_up_path(resource), after_sign_in_path(resource) and so on.

这篇关于用Devise登录后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆