Given that I have the following model:
class Profile
include ActiveModel::Validations
attr_accessor :avatar
validates :avatar, file_content_type: { allow: ['application/json'] }
end
I will get the following error message when the file is not valid:
|
allowed_file_content_types: ! 'file should be one of %{types}' |
With the allowed content type interpolated as specified in the validate statement, i.e. application/json as defined here:
|
error_options = options.merge(types: option_types.join(', ')) |
I suggest that we would convert the Mime type into human readable format, e.g. in this case JSON.
This could be done e.g. as follows:
"application/json".match(%r{/([a-z]+)})[1].upcase
Given that I have the following model:
I will get the following error message when the file is not valid:
file_validators/lib/file_validators/locale/en.yml
Line 10 in 55b8c7f
With the allowed content type interpolated as specified in the validate statement, i.e.
application/jsonas defined here:file_validators/lib/file_validators/validators/file_content_type_validator.rb
Line 88 in 55b8c7f
I suggest that we would convert the Mime type into human readable format, e.g. in this case
JSON.This could be done e.g. as follows: