2021-09-20 19:51:20 +02:00
|
|
|
module FileValidationConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
2021-09-28 16:05:49 +02:00
|
|
|
# This method works around missing `%{min_size}` and `%{max_size}` variables in active_record_validation
|
|
|
|
# default error message.
|
|
|
|
#
|
|
|
|
# Hopefully this will be fixed upstream in https://github.com/igorkasyanchuk/active_storage_validations/pull/134
|
2021-09-20 19:51:20 +02:00
|
|
|
def file_size_validation(file_max_size = 200.megabytes)
|
|
|
|
{ less_than: file_max_size, message: I18n.t('errors.messages.file_size_out_of_range', file_size_limit: ActiveSupport::NumberHelper.number_to_human_size(file_max_size)) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|