2016-07-28 13:54:17 -04:00
|
|
|
class UploadUrlValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
if value.present?
|
2018-03-28 04:20:08 -04:00
|
|
|
uri =
|
|
|
|
begin
|
|
|
|
URI.parse(value)
|
2018-08-14 06:23:32 -04:00
|
|
|
rescue URI::Error
|
2018-03-28 04:20:08 -04:00
|
|
|
end
|
2016-07-28 13:54:17 -04:00
|
|
|
|
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
|