1

我的 Rails 应用程序中有两个单独的登录模型:

  • 用户
  • 行政

我的 rake routes 输出是:rake routes | grep 设计

 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) 因为如果我写,所以我有日志:

Filter chain halted as :require_no_authentication rendered or redirected
4

1 回答 1

14
def after_sign_in_path_for(resource)
  case resource
  when User then request.referrer 
  when Admin then ....
  end
end
于 2012-12-30T17:30:52.873 回答