app/models/users/user.rb
def check_if_has_related_assets
    artifacts = %w(Account Campaign Lead Contact Opportunity Comment Task).inject(0) do |sum, asset|
      klass = asset.constantize
      sum += klass.assigned_to(self).count if asset != "Comment"
      sum += klass.created_by(self).count
    end
    artifacts == 0
  end
# Prevent deleting a user unless she has no artifacts left.
#----------------------------------------------------------------------------
Prevent deleting a user unless she has no artifacts left.
Prevent deleting a user unless she has no artifacts left .
def check_if_has_related_assets
    artifacts = %w(Account Campaign Lead Contact Opportunity Comment Task).inject(0) do |sum, asset|
      klass = asset.constantize
      sum += klass.assigned_to(self).count if asset != "Comment"
      sum += klass.created_by(self).count
    end
    artifacts == 0
  end
def check_if_has_related_assets artifacts = %w( Account Campaign Lead Contact Opportunity Comment Task ) . inject ( 0 ) do | sum , asset | klass = asset . constantize sum += klass . assigned_to ( self ) . count if asset != "Comment" sum += klass . created_by ( self ) . count end artifacts == 0 end
Prevent deleting a user unless she has no artifacts left.
Prevent deleting a user unless she has no artifacts left .