views:

74

answers:

3

I am working on an app right now where I have Individuals, Athletes and Coaches. A coach has many athletes and they create athletes as well. Whereas individuals can just come to the site and use a different set of tools. So for functionality and logic reasons I prefer to keep the individual model separate from the athlete model.

When users come to the site I want them to login but it would be confusing to have 3 logins (coach, individual and athlete). Users coming to the site will get confused whether or not they are an individual or an athlete. I was thinking of putting a login link which would have an ajax menu with all three choices, which will look nicer but I still have the multiple login issue.

Does anyone have an idea on how I can make ideally 1 login form for individuals and athletes. I am using authlogic for authentication. I am not looking for code, I can go in and mess around, just wondering if there is a trick to this (making it easier for the user).

Thanks!

+1  A: 

You might want to look at the devise gem (http://github.com/plataformatec/devise), this supports using multiple models for authentication.

Laz
A: 

Why not have the Individual, Athlete and Coach models be subclasses of your User model. Then you can put all the authentication guff into User and it's available to all three - all through the same login form.

Taryn East
Not bad, but subclasses break down if a user can be a Coach as well as an Athlete.
Jonathan Julian
Ok, in which case it sounds like you have user roles. However, this was not an element of the original request. ;)
Taryn East
A: 

You want to assign Roles to Users. You don't need separate subclasses for each user type, model it so a user has_many :roles.

Have a look at this blog post for a detailed explanation - roles can be very simple if this is all you need.

Jonathan Julian