I'm doing some research on how to handle multiple account types. In our app, we will have two types of accounts. Parents and Schools. These accounts will never change types, for example a Parent becoming a School.
Schools will have different relationships than Parents, but both will have the ability to login into their accounts (different UIs for both models).
I'm thinking in going with one Account per model, and have an account type to differenciate between Parents and Schools
class Account < ActiveRecord::Base # account_type in ["parent", "school"] end class School < ActiveRecord::Base has_many :accounts, as: :user end class Parent < ActiveRecord::Base has_one :account, as: :user end
Then the idea is to use Pundit to handle authorization
What do you think?, does this sounds like a good approach?
Would the Account be what the user logs into in your example?
I think that would make sense. You can then have multiple users for a single school (say several administrators) or even both parents could have separate accounts with your app.
Everyone could login through the same Account sign in form and then be redirected appropriately to the various views for parents or schools depending on their account type. That's probably the easiest experience for your users than having two separate login pages, one for parents only and another for schools only.
Yes, that's exactly what I want, Account will have the login information (username, password etc), and the records will reference either Parent or School.
I'll go ahead with this implementation and see how it goes.
Awesome, good luck and let us know how it goes! Only other thing I'd mention is you might want to change the name of Account to User so it's more standard for anyone working on the code later on. 🤘
I also have the same requirements the best solution i have found is using "devise + rolify+ cancancan" and then customise devise controller to add roles and after_sign_in_path on the basis of roles.
Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.