In my app I have different types of users/models which is configured via devise gem
for registration process. Let me make you more clear.
http://localhost:3000/doctor/sign_in
http://localhost:3000/hospital/sign_in
http://localhost:3000/user/sign_in
As all these have their own database tables like doctors
, hospitals
, users
in which all details are saved respectively.
Now what I want to know that Is that possible to have Single Login page and I login with registered doctor's id
then it should redirect me to Doctors
page, If I login with hospital's id
then it should redirect me to hospitals
page, so on.. Is that possible to achieve this? If yes then Can you please guide me in right direction what should I need to do?
Note: I am aware about managing roles/user_types
but I can not do that as there are different informations needed for doctors, hospitals and Users..
You can use Single Table Inheritance
class AuthUser < ActiveRecord::Base; end
class Doctor < AuthUser; end
class Hospital < AuthUser; end
class User < AuthUser; end
and use devise for AuthUser.
About after sign in path you can custom after_sign_in_path_for
. Sample
What I think that there should be only one for saving users, ie, users
. You can create a table named user_types
which will contain user type names, ie, doctor, hospital and user. User belongs to a User Type. It would look something like this
class User
belongs_to :user_type
end
class UserType
has_many :users
end
Then in application controller you can override devise's after_sign_in_path_for
method and redirect user to the page based on their user type.
Hope this makes sense!
or
If this is not possible then you can add three radio buttons for Doctor, User and Hospital, user will have to select it's login type along with the credentials before signing. Handle the login in the back end based on the value of the selected radio button.
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.