我正在处理角色/权限设置,但似乎无法按预期工作。Rails用户 - >角色 - >权限设置
class User < ActiveRecord::Base
has_and_belongs_to_many :roles, :join_table => "users_roles"
has_many :permissions, :through => :roles
class Role < ActiveRecord::Base
has_and_belongs_to_many :users
has_and_belongs_to_many :permissions, :join_table => "roles_permissions"
class Permission < ActiveRecord::Base
has_and_belongs_to_many :roles
我想什么是能够直接从我的用户对象(user.roles,user.permissions)访问角色和权限。
user.roles正在工作,但我似乎无法获得user.permissions工作。有没有人可以帮助我?
另一种方法是使用像Devise + CanCan这样的插件。然而,我对使用插件作为认证和授权至关重要的事情有一些担忧 - 如果它们停止使用会发生什么?任何对此有看法的人?
谢谢!
我会和CanCan一起去的。它是开源的,即使瑞恩贝茨停止了它的工作,其他人(也许你)可以也可能会这样做。它确实是你想要的而没有麻烦。 – polarblau 2011-02-11 15:07:41