# Best way to manage different settings model for different user roles?

**URL:** <https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423>\
**Category:** Rails\
**Created:** [March 9, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423 "2008-03-09T21:23:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marstoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@marstoni](https://www.ruby-forum.com/u/marstoni)\
**Post date:** [March 9, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423/1 "2008-03-09T21:23:42Z")

</div>

I’m looking for some input on the best way to support user settings  
when dealing with different user roles.

I have a Users model and in that have all the ‘required’ fields for a  
user. A given user can have a different role as well. Each role has  
vastly different misc settings we need to keep track of for that role.

Curious what would be the best way to keep all users in the Users  
model/table but still manage all the various role settings. Would it  
be best just to create separate models/tables for each role and just  
prefix it with the role name (i.e: role1\_settings, role2\_settings,  
role3\_settings etc) and glue them together with some AR/Association  
magic?

Only issue I see is if a user has multiple roles, though I might have  
to enforce 1 role per user. Anyways, thanks for any thoughts in  
advance.

---

<div class="post-metadata">

**Author:** ![marstoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@marstoni](https://www.ruby-forum.com/u/marstoni)\
**Post date:** [March 10, 2008, 1:33am UTC](https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423/2 "2008-03-10T01:33:45Z")

</div>

On Sun, 2008-03-09 at 13:22 -0700, Marston A. wrote:

> prefix it with the role name (i.e: role1\_settings, role2\_settings,  
> role3\_settings etc) and glue them together with some AR/Association  
> magic?
> 
> Only issue I see is if a user has multiple roles, though I might have  
> to enforce 1 role per user. Anyways, thanks for any thoughts in  
> advance.

* * *

I ended up using a methodology suggested but not completely delineated  
in Rails Recipes where there are Rights, Roles and Users.

Thus a User could have many Roles, and there are many Rights for each  
Role and thus the catch is that a User can only access methods that are  
specifically given to Rights via Roles that he is assigned to.

Craig

---

<div class="post-metadata">

**Author:** ![marstoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@marstoni](https://www.ruby-forum.com/u/marstoni)\
**Post date:** [March 10, 2008, 1:37am UTC](https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423/3 "2008-03-10T01:37:16Z")

</div>

seems like you would probably want to create a role\_settings table  
with

id  
role\_id  
setting\_name

and a user\_role\_settings table

id  
user\_id  
role\_setting\_id  
value

then you can create your user, assign them some roles using a habtm  
relationship between the users and roles tables

Roles can then take any number of settings, via the role\_settings  
table (belongs\_to/has\_many relationship), which means you’re never  
limited to the number of settings a role can take

You can then store the user’s settings in the user\_role\_settings  
table, which would be governed by the roles that a user had assigned.  
(if needed, you could add role\_id in there to speed up joins)

If you wanted to store enumerations for a role\_setting you could make  
another table role\_setting\_values with role\_id / value.

I remember setting up something like this in ASP and it was a bit of a  
headache but in rails it should be child’s play.

If you need a good start with users/role based authentication, get  
hold of restful\_authentication and add acl\_system2 plugin which will  
give you simple role management. The rest of the above would give you  
the power to leverage bespoke settings for roles and let your users  
manage them.

Hope this assists?

---

<div class="post-metadata">

**Author:** ![marstoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@marstoni](https://www.ruby-forum.com/u/marstoni)\
**Post date:** [March 10, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/best-way-to-manage-different-settings-model-for-different-user-roles/131423/4 "2008-03-10T13:07:31Z")

</div>

Might want to check out the acl\_system2 plugin.
