# Role based authentification

**URL:** <https://www.ruby-forum.com/t/role-based-authentification/102637>\
**Category:** Rails\
**Created:** [December 31, 2006, 12:40am UTC](https://www.ruby-forum.com/t/role-based-authentification/102637 "2006-12-31T00:40:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CSSSSdric\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f6c823/32.png) [@CSSSSdric\_H](https://www.ruby-forum.com/u/CSSSSdric_H)\
**Post date:** [December 31, 2006, 12:40am UTC](https://www.ruby-forum.com/t/role-based-authentification/102637/1 "2006-12-31T00:40:41Z")

</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"
