当使用CanCan gem进行授权时,模型/数据库应该是什么样子?



我使用设计作为授权。并且想知道模型和数据库应该如何。在这集ailcast中http://railscasts.com/episodes/192-authorization-with-cancan说Ryan在角色和用户之间使用多对多。

My User model:'

class User < ActiveRecord::Base
has_and_belongs_to :roles
has_many :posts
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

我的榜样:

class Role < ActiveRecord::Base
has_and_belongs_to :users
end

但是角色表应该是什么样的呢?

我正在考虑创建这样的角色表:

id
admin - Boolean
moderator - Boolean
author - Boolean 

然后表roles_users:

id 
role_id
user_id

但是为什么一个用户应该有很多角色呢?当有布尔值时?

角色表应该是:

id
role_name

相关内容

最新更新