# Class inheritance and AAA

**URL:** <https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945>\
**Category:** Rails\
**Created:** [May 24, 2007, 7:26am UTC](https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945 "2007-05-24T07:26:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mauo](https://www.ruby-forum.com/u/mauo)\
**Post date:** [May 24, 2007, 7:26am UTC](https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945/1 "2007-05-24T07:26:58Z")

</div>

Hi all,

I’m somewhat new with RoR, but have been programming for a while. I’m  
trying to design the right model for an application which will have a  
login system, I’m leaning towards acts\_as\_authenticated.

I have one confusion, though… In my app, I want to have one login  
system which will allow general Clients and Employees to login. These  
have all similar characteristics shared with the User table created  
by AAA, but also have other methods and behaviors to deal with the  
rest of my app.

How should I define the Client model, for instance? Would it be  
something like:

class Client \< User

since I already have user.rb defining the User class as such:

class User \< ActiveRecord::Base

or would I be forced to compromise and create different Client and  
Employee tables and models, each with its own salt, hashed\_passwords  
and the like?

I figure by inheriting from User, I should be able to define the User  
model with all the relevant methods and properties. Must I have all  
the classes in the same file, or am I able to have a client.rb file  
where I inherit User?

Thanks for any help in advance,  
Mauricio

* * *

Mauricio L. Sadicoff  
removed\_email\_address@domain.invalid

“Peace of mind isn’t at all superficial, really,” I expound. “It’s  
the whole thing. That which produces it is good maintenance; that  
which disturbs it is poor maintenance. What we call workability of  
the machine is just an objectification of this peace of mind. The  
ultimate test is always your own serenity.” - Zen and the Art of  
Motorcycle Maintenance.

---

<div class="post-metadata">

**Author:** ![mauo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mauo](https://www.ruby-forum.com/u/mauo)\
**Post date:** [May 24, 2007, 10:53am UTC](https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945/2 "2007-05-24T10:53:44Z")

</div>

On 5/23/07, Mauricio S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> by AAA, but also have other methods and behaviors to deal with the  
> rest of my app.  
> […]

Hi Mauricio,

What you’re describing sounds very much like role-based authorization  
to me. Your Clients and Employees do not necessarily have to be  
first-class models; they are both Users, but they belong in different  
roles because they do not have the same access to resources.

How you implement this kind of role separation is up to you – in some  
of my apps, I have just a text field on my User model that contains  
the name of a role; in others, I have a table of Roles, and my User  
model belongs\_to :role (i.e., it has a role\_id field). In still  
others, where users can be in many roles and the relationship is a  
many-to-many, I use a join model, like “Membership”, which has a  
user\_id and a role\_id.

Another way to get started might be to look at Bill K.'s  
Authorization plugin (  
[writertopia](http://www.writertopia.com/developers/authorization) ). I don’t know  
if he’s been doing much work on it lately, but it’s certainly worth  
looking at, as it may help with your concerns.

Regards,

Seth Morabito

---

<div class="post-metadata">

**Author:** ![mauo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mauo](https://www.ruby-forum.com/u/mauo)\
**Post date:** [May 24, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945/3 "2007-05-24T16:57:20Z")

</div>

Here’s an overview of several authorization solutions for rails  
[http://www.vaporbase.com/postings/Authorization\_in\_Rails](http://www.vaporbase.com/postings/Authorization_in_Rails)

---

<div class="post-metadata">

**Author:** ![mauo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mauo](https://www.ruby-forum.com/u/mauo)\
**Post date:** [May 26, 2007, 4:59am UTC](https://www.ruby-forum.com/t/class-inheritance-and-aaa/104945/4 "2007-05-26T04:59:18Z")

</div>

Thank you so much, Seth and Linoj.

I don’t know why I didn’t think of RBAC before, it’s definitely what  
I need.

So I’ll just use the authentication provided by AAA, then setup an  
authorization system based on the Membership model, which then allows  
me to redirect the user to the right controller depending on the  
current role the User assumes. I actually considered using Goldberg,  
but that would defeat my purpose of learning more about Rails, so  
I’ll build it from scratch.

Thanks again, guys, super helpful!

Cheers,  
Mauricio

* * *

Mauricio L. Sadicoff  
removed\_email\_address@domain.invalid

“Peace of mind isn’t at all superficial, really,” I expound. “It’s  
the whole thing. That which produces it is good maintenance; that  
which disturbs it is poor maintenance. What we call workability of  
the machine is just an objectification of this peace of mind. The  
ultimate test is always your own serenity.” - Zen and the Art of  
Motorcycle Maintenance.

On May 24, 2007, at 03:52, Seth Morabito wrote:

> What you’re describing sounds very much like role-based authorization  
> to me.
