Orlando Del Aguila

Joined

860 Experience
8 Lessons Completed
0 Questions Solved

Activity

Posted in Handling multiple Account types

Chris,

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.

Thanks!

Posted in Handling multiple Account types

Hello Guys,

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?

Thanks!

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.