I’m trying to build a application that has different kinds of users, I’m using authlogic for user authentication.
So I have one user model that has the required field for authlogic to do its magic. I now want to add a couple of different models that would describe the extra fields for the different kinds of users.
Lets say that a user registers, he would then select his user type, when he is done registering he would be able to add information that is specific for his user model.
What would be the best way to do this? I am currently looking into polymorphic models but I’m not sure that’s the best route to take. Any help would be greatly appreciated, thanks.
You can create different
profiletables and just tie the profile to the user. So for each user type you can create a table and store the specific info there and have auser_idcolumn to point back tousers.Now this isn’t very DRY and could lead to problems if you are constantly adding user types. So you could look into polymorphism.
For polymorphism, the
userstable would define what type the user is (profileable_idandprofileable_type). So something like this:Then there is a third option of STI (single table inheritance) for the user types. But that doesn’t scale well if the user type fields differ dramatically.