繁体   English   中英

为其他模型设计after_sign_in_path_for

[英]Devise after_sign_in_path_for for other model

我的rails应用程序中有两个分开的登录模型:

  • 用户
  • 管理员

我的耙路输出: grep devise

 new_admin_session GET    /admins/sign_in(.:format)                                                 devise/sessions#new
                  admin_session POST   /admins/sign_in(.:format)                                                 devise/sessions#create
          destroy_admin_session DELETE /admins/sign_out(.:format)                                                devise/sessions#destroy
               new_user_session GET    /users/sign_in(.:format)                                                  devise/sessions#new
                   user_session POST   /users/sign_in(.:format)                                                  devise/sessions#create
           destroy_user_session DELETE /users/sign_out(.:format)                                                 devise/sessions#destroy
                  user_password POST   /users/password(.:format)                                                 devise/passwords#create
              new_user_password GET    /users/password/new(.:format)                                             devise/passwords#new
             edit_user_password GET    /users/password/edit(.:format)                                            devise/passwords#edit
                                PUT    /users/password(.:format)                                                 devise/passwords#update
       cancel_user_registration GET    /users/cancel(.:format)                                                   devise/registrations#cancel
              user_registration POST   /users(.:format)                                                          devise/registrations#create
          new_user_registration GET    /users/sign_up(.:format)                                                  devise/registrations#new
         edit_user_registration GET    /users/edit(.:format)                                                     devise/registrations#edit
                                PUT    /users(.:format)                                                          devise/registrations#update
                                DELETE /users(.:format)                                                          devise/registrations#destroy

在ApplicationController中我有

 def after_sign_in_path_for(resource)
    request.referrer 
  end

它对我的用户模型非常有用,但是如何对我的管理员模型有效,因此登录后我将重定向到同一页面(我使用内置的after_admin_sign_in_path_for(resource)控制器),例如after_admin_sign_in_path_for(resource)因为如果我这样写,我有日志:

Filter chain halted as :require_no_authentication rendered or redirected
def after_sign_in_path_for(resource)
  case resource
  when User then request.referrer 
  when Admin then ....
  end
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM