Ask A Question

Notifications

You’re not receiving notifications from this thread.

User model guidance

Stephen Sizer asked in Rails

Hi All,

I'm creating a coaching app and have two users that use the system a coach and a client. A coach can also be a client of another coach. So I will need to be able to switch accounts to either the client or the coach.

Coach:
has_many :clients

Client:
belongs_to :coach

What would be the best way to do this? Having two Devise models Coach and Client or having two boolean fields on the user to say is_coach, and is_client.

If a coach has an account and then is added as a client, I want that client account to have the same password as the coach account for ease of use.

Thanks,
Stephen

Reply

Hey Stephen!

The way I do it in JumpstartRails.com is we have a single User everyone logs in as and they have multiple Accounts they're associated with.

Each account could have a type of Coach, Client, etc and they switch between them with a session cookie. When they switch, we use current_account to load the account and we could use that to determine if they should see Coach or Client views.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.