Ask A Question


You’re not receiving notifications from this thread.

Multiple Users with Devise

Ja Ku asked in Gems / Libraries

Hello! I'm new here. I'm currently working on an app and I'm trying to wrap my mind around how I want to handle authentication using Devise. I've read the past threads that were similar to my situation but I figured I'd ask anyways since I'm still a bit confused.

The overall purpose of the app is for two different types of users (ex. student or teacher) to communicate with each other through messaging (granted that they have both added each other to their networks).

My goal:

I would like to have someone sign up, decide what type of user they are (ex. student or teacher), and depending on which one they choose they would have to fill out specific profile information relevant to that type of user via a redirect once the user has been created. Students and teachers have different types of profiles they need to fill out.

I would like to have people sign in using one form if possible, and have the form know which type of user just logged in and redirect them to the dashboard view associated with that type of user.

For the sake of the user example, student and teachers have different pages they can access that are unique to their user.

If there are any questions about what I'm trying to do here, feel free to ask and I'll clarify.

Thank you!


Welcome! :)

The simplest way to go about this is probably to create just one User type but add a role attribute to it. Just make it a string to keep it simple. When you sign up, you can choose either Student or Teacher. Depending on hwich one you select, submit the string "student" or "teacher" for the role field so it can get saved to the database.

You can use that role attribute to redirect them easily. Then you can have to different types of profiles in your database. StudentProfile, and TeacherProfile. You can put any of the fields you want to have on those, and then ask them to fill out the correct type of profile after signing up based on their role.

Let me know how it works out!


Hi Chris!

How would you model those profiles?
I understand that is an optional extension, but I'm not sure yet how to shape that concept. An additional model?

In my case every profile has a different set of attributes, and getting all of them in the same model would be a mess. What would be the proper way?


Yeah, I'd probably do an additional model. User has_one :student_profile and you can create that after they register or something.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.