def validate_each(record, attribute, value)
      unless value.blank?
        unless value =~ VALID_MASK
          if value =~ /\A[^a-z]/i
            record.errors[attribute] << (options[:message] || 'must start with a letter')
          elsif value =~ /_\z/
            record.errors[attribute] << (options[:message] || 'must not end with an underscore')
          else
            record.errors[attribute] << (options[:message] || 'must contain only letters, numbers, and underscore')
          end
        end
      end
    end
def validate_each(record, attribute, value)
      unless value.blank?
        unless value =~ VALID_MASK
          if value =~ /\A[^a-z]/i
            record.errors[attribute] << (options[:message] || 'must start with a letter')
          elsif value =~ /_\z/
            record.errors[attribute] << (options[:message] || 'must not end with an underscore')
          else
            record.errors[attribute] << (options[:message] || 'must contain only letters, numbers, and underscore')
          end
        end
      end
    end
Validates attributes to determine if the values match the requirements of a safe name.