In the app, both the
Contact model and the
Company model need to be able to log in. The things they can see and do are completely separate (but who knows how the app will evolve later on). So far I’ve only implemented the logging in functionality for the
Contact model, not the
Just yesterday, I learned what a polymorphic association is. Now, I wonder if I should scrap my original plan to have two models that can log in separately, and instead have just one
User model, with a polymorphic association to the
On the one hand, the Devise GitHub page only talks about multiple model logins. On the other hand, most posters on StackExchange seem to be using polymorphic associations instead of multiple models.
I am leaning towards using polymorphic associations, because I already have role-based authorization implemented with CanCan for contacts. I could just add another role for “company-type” users. I can imagine this approach is more scalable. Right now having two separate Models that can log in doesn’t seem so bad, but if later on more and more Models start needing to log in, I would much rather just one row to a “roles” table, rather than having to implement login functionality separately for each of those Models.