paperclip

https://github.com/thoughtbot/paperclip

Ruby

Easy file attachment management for ActiveRecord

Paperclip::Validators::HelperMethods#validates_attachment_content_type

Places ActiveModel validations on the content type of the file
assigned. The possible options are:
* +content_type+: Allowed content types.  Can be a single content type
  or an array.  Each type can be a String or a Regexp. It should be
  noted that Internet Explorer uploads files with content_types that you
  may not expect. For example, JPEG images are given image/pjpeg and
  PNGs are image/x-png, so keep that in mind when determining how you
  match.  Allows all by default.
* +not+: Forbidden content types.
* +message+: The message to display when the uploaded file has an invalid
  content type.
* +if+: A lambda or name of an instance method. Validation will only
  be run is this lambda or method returns true.
* +unless+: Same as +if+ but validates if lambda or method returns false.
NOTE: If you do not specify an [attachment]_content_type field on your
model, content_type validation will work _ONLY upon assignment_ and
re-validation after the instance has been reloaded will always succeed.
You'll still need to have a virtual attribute (created by +attr_accessor+)
name +[attachment]_content_type+ to be able to use this validator.

Source | Google | Stack overflow

Edit

git clone [email protected]:thoughtbot/paperclip.git

cd paperclip

open lib/paperclip/validators/attachment_content_type_validator.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Paperclip--Validators--HelperMethods-validates_attachment_content_type-for-pr


# Commit to git

git add lib/paperclip/validators/attachment_content_type_validator.rbgit commit -m "better docs for Paperclip::Validators::HelperMethods#validates_attachment_content_type"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Paperclip--Validators--HelperMethods-validates_attachment_content_type-for-pr

hub pull-request


# Celebrate!