简体   繁体   中英

Devise multiple model session in same browser

I have two devise model User and Admin . Now does devise support multiple model session in same browser in different tabs. If yes than how can i assign two different layout with two session in progress.

I tried this

layout :layout_by_resource

def layout_by_resource
 if devise_controller? and admin_signed_in?
   'admin'
 elsif devise_controller? and user_signed_in?
  'user'
 else
   'application'
 end
end

but this won't work because admin and user both already signed in.

If devise does not support two different model session in same browser then what is the purpose of using devise and how can i accomplish my requirement.

If you follow this https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-Role

You can simply check current_user.admin?

def layout_by_resource
 if current_user.admin?
   'admin'
 elsif current_user
  'user'
 else
   'application'
 end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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