Class: MiniPaperclip::Validators::MediaTypeSpoofValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- MiniPaperclip::Validators::MediaTypeSpoofValidator
- Defined in:
- lib/mini_paperclip/validators/media_type_spoof_validator.rb
Instance Method Summary collapse
Instance Method Details
#normalize(content_type) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/mini_paperclip/validators/media_type_spoof_validator.rb', line 15 def normalize(content_type) case content_type when "image/jpg" "image/jpeg" else content_type end end |
#validate_each(record, attribute, attachment) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/mini_paperclip/validators/media_type_spoof_validator.rb', line 6 def validate_each(record, attribute, ) return unless . = record.read_attribute_for_validation("#{attribute}_content_type") unless normalize(.) == normalize() record.errors.add(attribute, :spoofed_media_type) end end |