mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-12 00:31:48 -05:00
12 lines
295 B
Ruby
12 lines
295 B
Ruby
|
class UrlValidator < ActiveModel::EachValidator
|
||
|
def validate_each(record, attribute, value)
|
||
|
if value.present?
|
||
|
uri = URI.parse(value) rescue nil
|
||
|
|
||
|
unless uri
|
||
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid'))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|