# Adding permissions

**URL:** <https://www.ruby-forum.com/t/adding-permissions/129486>\
**Category:** Rails\
**Created:** [February 19, 2008, 12:06am UTC](https://www.ruby-forum.com/t/adding-permissions/129486 "2008-02-19T00:06:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trejkaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@trejkaz](https://www.ruby-forum.com/u/trejkaz)\
**Post date:** [February 19, 2008, 12:06am UTC](https://www.ruby-forum.com/t/adding-permissions/129486/1 "2008-02-19T00:06:16Z")

</div>

Hi all.

I have an app which already uses a user table for authentication. In  
the early days I added extra boolean columns for flags indicating user  
permissions (admin, etc.) which worked quite well up to a point.

Now the number of permission flags is increasing so I’m curious as to  
where I should go from here…

1. Keep adding boolean columns (simple, but is there a drawback of  
having too many columns?)

2. Have some kind of :roles table and create a join table to  
link :users to :roles (probably cleaner but does mean either doing  
joins all the time, or executing a new query each time you check a  
permission.)

3. Have a :roles column in the :users table and store a YAML structure  
with all the roles in a set of some sort.

Problem is I like all three options. Which of these would be  
considered the most “Rails-like” way to go about things?

TX

---

<div class="post-metadata">

**Author:** ![trejkaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@trejkaz](https://www.ruby-forum.com/u/trejkaz)\
**Post date:** [February 19, 2008, 12:41am UTC](https://www.ruby-forum.com/t/adding-permissions/129486/2 "2008-02-19T00:41:52Z")

</div>

> Problem is I like all three options. Which of these would be  
> considered the most “Rails-like” way to go about things?

If it were up to me, I’d go the join table route, using has\_many,  
:through. So it would look similar to:

Class User  
has\_many :roles, :through =\> :permissions  
End

Class Role  
has\_many :users, :through =\> :permissions  
End

Class Permissions  
belongs\_to :roles  
belong\_to :users  
End

The benefit of using this is that it gives you a whole new model object  
to work with, should the permissions system ever need to be more  
complicated. Your join table would have a role\_id and user\_id, but could  
also contain other columns if needed. I think this would be the most  
flexible options, and is probably the most Rails-like.

---

<div class="post-metadata">

**Author:** ![trejkaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@trejkaz](https://www.ruby-forum.com/u/trejkaz)\
**Post date:** [February 19, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/adding-permissions/129486/3 "2008-02-19T16:17:42Z")

</div>

Join table would be my second best option. Top on my list would be to  
check out the acl\_system or acl\_system2 plugin so I wouldn’t have to  
write it myself!

On Feb 18, 6:41 pm, “Bryan M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
