[英]Rails how should the model/database be like when using the CanCan gem for Authorization?
我正在使用devise作為授權。 並且想知道模型和數據庫應該如何。 在此ailscasts情節中, http ://railscasts.com/episodes/192-authorization-with-cancan說Ryan在角色和用戶之間使用了很多對很多。
我的用戶模型:'
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
然后表role_users:
id
role_id
user_id
但是,用戶為什么要扮演許多角色? 什么時候吃布爾值?
角色表將是:
id
role_name
這樣,您可以添加角色而無需更改架構。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.