2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00
discourse/lib/validators/upload_url_validator.rb

16 lines
382 B
Ruby
Raw Normal View History

class UploadUrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.present?
uri =
begin
URI.parse(value)
rescue URI::Error
end
unless uri && Upload.exists?(url: value)
record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
end
end
end
end