用Devise登录后重定向

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

谢谢!

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

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

只需将此方法添加到应用程序控制器中即可

 def after_sign_in_path_for(resource) user_path(current_user) #your path end 

只将以下代码粘贴到应用程序控制器或任何控制器,您需要进行操作;

 def after_sign_in_path_for(resource) users_path end 

以下是我认为你正在寻找的设计维基的答案:

方法:更改默认的sign_in和sign_out路由