My Goal:
I'm trying to create two different types of users, with different profiles.
Barber
, Client
, BarberProfile
, and ClientProfile
I have my base User
object that contains information like email
, password
, and all the other fields that Devise keeps track of.
I'd like the base User
model to have one Profile
that keeps track of all basic information that I want all my users to have. For instance, first_name
, last_name
, avatar
, etc.
I'm using single table inheritance to create two different types of users: Client
and Barber
.
I want each of these types of users to have a base Profile
associated with it, and then have additional fields that belong to a BarberProfile
and a ClientProfile
, respectively.
The BarberProfile
will have things that the Barber
needs, but the Client
doesn't. For instance, a bio
. The ClientProfile
will have things the Client
needs, but the Barber
doesn't. For instance, hair_type
.
What I currently have, and my problem:
As stated above, I've created a table for User
and Profile
. So I'm able to call user.profile.first_name
. I created a BarberProfile
and ClientProfile
table in order to add the extra fields.
I'd like to just be able to reference user.profile.bio
if the user type is Barber
. But bio
isn't a part of the base profile. So in this case I'd have to create an associated Profile
and and associated BarberProfile
to get everything I need. I could just do user.profile.first_name
and user.barber_profile.bio
, but it feels messy, and I'm making two different associations from essentially the same type of model. I feel like it should be a simple thing to just have the BarberProfile
inherit all fields from Profile
and add its own specific Barber
fields on top.
How does one go about doing this in Rails?
Edit: One of the main reasons I want to do this is so I can update things like first_name
and bio
within the same form for a Barber
. And similarly, a first_name
and hair_type
within the same form for a Client
.