# Role based authentification

**URL:** <https://discuss.rubyonrails.org/t/role-based-authentification/6245>\
**Category:** rubyonrails-talk\
**Created:** [December 23, 2006, 1:03am UTC](https://discuss.rubyonrails.org/t/role-based-authentification/6245 "2006-12-23T01:03:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cedric\_H](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cedric\_H](https://discuss.rubyonrails.org/u/Cedric_H)\
**Post date:** [December 23, 2006, 1:03am UTC](https://discuss.rubyonrails.org/t/role-based-authentification/6245/1 "2006-12-23T01:03:12Z")

</div>

Hi,

This is about this book : [http://www.pragmaticprogrammer.com/titles/fr\_rr/index.html](http://www.pragmaticprogrammer.com/titles/fr_rr/index.html)

The recipe #32 is about creating a role based authentification.

In the book, we use 3 tables:

"user" wich has and belongs to many "role" wich has and belongs to many "right":

class User \< ActiveRecord::Base has\_and\_belongs\_to\_many :roles end class Role \< ActiveRecord::Base has\_and\_belongs\_to\_many :users has\_and\_belongs\_to\_many :rights end class Right \< ActiveRecord::Base has\_and\_belongs\_to\_many :roles end

But I think it is better to set something like that:

class Right \< ActiveRecord::Base has\_many :roles has\_many :users, :through =\> :roles end class User \< ActiveRecord::Base has\_many :roles has\_many :right, :through =\> :roles end class Role \< ActiveRecord::Base belongs\_to :group belongs\_to :user end

Do you think it is better ?

IMHA It looks more " Rails 1.2"
