Имеем стандартные модели для плагина acl_system Account, AccoutRole, AccountRoleRelationship
Хотим получить приятный интерфейс для управления ролями.
@account.roles.grant(@role1, @role2)
@account.roles.revoke(@role)
@account.roles.revoke_all
Получим вот такой вот замечательный код.
class Account < ActiveRecord::Base
module Roles
def grant(*roles)
self < @owner.id)
reload
end
end
has_many :roles_relationships,
:class_name => 'AccountRoleRelationship',
:dependent => :destroy
has_many :roles,
:through => :roles_relationships,
:uniq => true do
include Roles
end
end
class AccountRole 'AccountRoleRelationship',
:dependent => :destroy
has_many :accounts,
:through => :account_relationships
end
class AccountRoleRelationship 'AccountRole',
:foreign_key => 'account_role_id'
validates_presence_of :account_id, :account_role_id
end
Нужно отметить, что в Edge Rails исправлен баг , о котором писал Равиль, но почему то не исправлен баг с destroy_all


(5 votes, average: 3.4 out of 5)








Зачот)
Лаконично. Ни 1 слова!
гы-гы