Role based authentification


#1

Hi,

This is about this book :
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"