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

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

问题描述

使用Devise登录后,是否可以将用户重定向到其他页面(基于角色)?似乎只重定向到route.rb中定义的root:to => ...页面。

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-Signin

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(资源) after_sign_in_path(资源)等。

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.

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

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