Forum: Ruby on Rails Role based authentification

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cédric H. (Guest)
on 2006-12-31 01:40
(Received via mailing list)
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"
This topic is locked and can not be replied to.