Class: ActiveModel::Validations::UrlValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::UrlValidator
- Defined in:
- lib/can_has_validations/validators/url_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/can_has_validations/validators/url_validator.rb', line 7 def validate_each(record, attribute, value) if defined?(Addressable::URI) u = Addressable::URI.parse(value) rescue nil else u = URI.parse(value) rescue nil end if !u || u.relative? || %w(http https).exclude?(u.scheme) record.errors.add(attribute, :invalid_url, ) end end |