views:

96

answers:

1

I'm working on a new project and for some reason decided to create two separate user models/controllers/sessions using authologic.

The users have completely different roles on the site but the models are basically the same. The only difference is the views.

I'm now wondering if I should have just created one model and added a "role" field. Then after they log in, figure out which role they have, and then dump them to a new controller based on their role.

So I guess my question is, is there any reason to have two user models? Are there any guides about user roles with authlogic?

Thanks!

+3  A: 

Since Authlogic is soley focused on authentication, it is very easy to add role-based permissions. We did this quite simply by having a single User model, adding a Role model, and then having a UserRole model that linked the two which allowed the same user to have multiple roles, and also for multiple users to have the same role.

From Authlogic's standpoint, it doesn't care. It only lets you know that the user is authenticated, so any permissions you add on top of that are your own.

There are plenty of articles available on role-based permissions in RoR, so just Google it and I'm sure you will find a few that suite your needs.

From what I have found though, keeping it simple will greatly help your life :-)

Topher Fangio
Thank you, that's enough to convince me to keep one model. However,there's a two level hierarchy also, which was much simpler with two models. One model has_many of the other, which belongs_to the first. Having one model I'm finding I have to do some funky :through stuff, but In a month I'm sure I'd be kicking myself with two models.
rpflo
You might look at using single table inheritance if it makes sense for you to separate some of the business logic. For instance, you might have a User model and a SpecialUser model that inherits from User. They both use the same table for data, but it allows you to separate some of the logic. Anywhere you want, you can treat a SpecialUser as a User to simplify your code :-)
Topher Fangio