Tags

, , ,

In this short tutorial, I will explain you how you can add custom validation messages on the Attachment if you’re using Paperclip plugin or gem.

Way 1. This will work if you’re running your rails application on Windows Machine.
Solution: a) install mimetype-fu plugin.
b) Once installed, open Model, where paperclip settings has been defined. In my case, its User Model. Open it and add:

has_attached_file :avatar
validate :prohibited_ext
protected
def prohibited_ext
errors.add(:avatar, “Format #{File.mime_type?(avatar.path)} is invalid!”) unless File.mime_type?(avatar.path) == “application/exe”
end

Advertisements