Rails:设计:按角色登录后重定向 [英] Rails: Devise: redirect after sign in by role

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

问题描述

是否可以在使用 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.

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

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