2016-07-28 13:54:17 -04:00
|
|
|
class UploadUrlValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
if value.present?
|
|
|
|
uri = URI.parse(value) rescue nil
|
|
|
|
|
2016-09-21 23:29:44 -04:00
|
|
|
unless uri && Upload.exists?(url: value)
|
2016-07-28 13:54:17 -04:00
|
|
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|