Added meta where and jquery observe field. Fixed members view.

This commit is contained in:
benni 2011-05-15 23:43:23 +02:00
parent 6c98c7c755
commit c87ead8da9
10 changed files with 102 additions and 51 deletions

View file

@ -2,12 +2,16 @@ class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :group
before_destroy :check_last_admin
# messages
ERR_NO_ADMIN_MEMBER_DELETE = "Mitgliedschaft kann nicht beendet werden. Du bist die letzte Administratorin"
protected
# check if this is the last admin-membership and deny
def before_destroy
def check_last_admin
raise ERR_NO_ADMIN_MEMBER_DELETE if self.group.role_admin? && self.group.memberships.size == 1 && Group.find_all_by_role_admin(true).size == 1
end
end