Class: UrlValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/flash_validators/validators/url_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
# File 'lib/flash_validators/validators/url_validator.rb', line 4

def validate_each(record, attribute, value)
  uri = URI.parse(value)
  raise URI::InvalidURIError unless valid?(uri, options)
rescue URI::InvalidURIError
  record.errors[attribute] << (options[:message] || I18n.t('flash_validators.errors.messages.url'))
end