lib/rbacan/permittable.rb in rbacan-0.1.1 vs lib/rbacan/permittable.rb in rbacan-0.1.2

- old
+ new

@@ -9,10 +9,11 @@ has_many :user_roles, class_name: Rbacan.user_role_class, dependent: :destroy has_many :roles, class_name: Rbacan.role_class, through: :user_roles def assign_role(role_name) assigned_role = Rbacan::Role.find_by_name(role_name) - Rbacan::UserRole.create(user_id: self.id, role_id: assigned_role.id) + self.user_roles.find_or_create_by(role_id: assigned_role.id) + self.save if self.persisted? end def remove_role(role_name) removed_role = Rbacan::Role.find_by_name(role_name) Rbacan::UserRole.where(user_id: self.id, role_id: removed_role.id).destroy_all