Class: UrlValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UrlValidator
- Defined in:
- app/models/url_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'app/models/url_validator.rb', line 2 def validate_each(record, attribute, value) if value =~ /\Ahttps?:\/\/[^\n]+\z/i url = ::Addressable::URI.parse(value) unless ['http', 'https'].include?(url.scheme) record.errors.add(attribute.to_sym) end else record.errors.add(attribute.to_sym) end end |