2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00
discourse/lib/validators/url_validator.rb

12 lines
295 B
Ruby
Raw Normal View History

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