Different Usermodels with Authlogic + Declarative Authorizat

Hi there,
I'm working on a Rails App, in which I use the gems Authlogic and
Declarative Authorization to put Users into different roles.

But because the roles are very different from each other, I thought it
would be better, if every usertype gets its own databasetable / model.

The model [b]Student[/b] has for example the attributes: Name, Birthday,
E-Mail, Grades, Schools, Lessions, Awards and many many more.
But the model [b]Teacher[/b] has only Name, Birthday, E-Mail
The [b]Admin[/b] model gets just Name and E-Mail.

[b]Now my Problem:[/b]
Declarative Authorization and many other authorization-systems, that I
looked in, only working with one Usermodel, in which different roles get
This would mean, that even Teachers and Admins would have the Attributes
of the Students (but with no Values, which makes validations difficult).
I would like to know, how I can separate Students, Teachers and Admins
into different user models and get it to work with Authlogic and
Declarative Authorization.

I would like to use commands like Teacher.find_by_name('Bob') or

Do you know the answer and can you show me some code examples?

Have you thought about using Single Table inheritance (STI) for the
User model? A Google search of "rails single table inheritance" will
yield some good tutorials.

One of the big reasons for not using STI is if your models are very
different with regards to attributes of the sub classes that get
stored in the Users table but from your description below they don't
seem that different if you disregard the associations (Grades,
Schools, Lessons, etc) because the associations will be implemented
with either linking tables (has_and_belongs_to_many or
has_many :through) or foreign keys on the Grades, Schools, Lessons,
etc tables (has_many on User end and belongs_to on the other end) and
not in columns in the Users table.

Maybe you could check out implementing STI and let me know if it works

I have never used STI with Declarative Authorization but I'm guessing
that since you'll have one base class (User) it should work out since
I believe that you can define the roles on the base class.

I am using STI on a project with a User model and it works well.


I'm going with Devise now, since it can make different models
"authenticatable" :slight_smile:

Mike Gehard wrote: