def has_unique_name
      invalid = false
      if template
        invalid ||= template.common_fields.any? {|field| field.name.downcase == self.name.downcase && field != self }
        invalid ||= template.default_fields.any? {|field| field.name.downcase == self.name.downcase && field != self }
      else
        scope = self.class.common.where("LOWER(name) = LOWER(?)", self.name)
        scope = scope.where("id != ?", self.id) if persisted?
        invalid ||= scope.exists?
      end

      errors.add(:name, "has already been taken") if invalid
    end
def has_unique_name
      invalid = false
      if template
        invalid ||= template.common_fields.any? {|field| field.name.downcase == self.name.downcase && field != self }
        invalid ||= template.default_fields.any? {|field| field.name.downcase == self.name.downcase && field != self }
      else
        scope = self.class.common.where("LOWER(name) = LOWER(?)", self.name)
        scope = scope.where("id != ?", self.id) if persisted?
        invalid ||= scope.exists?
      end

      errors.add(:name, "has already been taken") if invalid
    end
Checks the current template and the common fields for any field with the same name