Muhammad Faisal Iqbal Muhammad Faisal Iqbal - 1 year ago 95
Ruby Question

Conditional Route on sign_out using Devise with Rails

I am working on an app in which there is a model User with roles member and Admin.

As per requirement, I have to made two separate login pages for Admin and Member.



it goes to admin login page and with


it goes to member login page.
Just after login I route them according to their roles to Admin panel or simple website for members.

But at time of logout both goes to

but I want admin to go to
is fine for member's logout.

Is there a way to see User's Role at time of Sign_out and route them accordingly.

Answer Source

To avoid sign_out to clear all sessions you can use

config.sign_out_all_scopes = false

in devise.rb than it will not clear all sessions.

Than at time of sign_in create as session like

session["Role"] = "Admin" etc

and in logout check the session and route accordingly

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download