The code powering m.abunchtell.com https://m.abunchtell.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

15 行
394 B

  1. # frozen_string_literal: true
  2. class UrlValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. record.errors.add(attribute, I18n.t('applications.invalid_url')) unless compliant?(value)
  5. end
  6. private
  7. def compliant?(url)
  8. parsed_url = Addressable::URI.parse(url)
  9. parsed_url && %w(http https).include?(parsed_url.scheme) && parsed_url.host
  10. end
  11. end