Atari2600
Atari2600

Reputation: 1239

Rails Paperclip File Type Validation - Add PDF?

I have the validation setup for only allowing png, and jpg, but I would also like to allow PDF's. I cannot seem to figure out how to add that syntax to the existing code.

  has_attached_file :receipt
  # Validate content type
  validates_attachment_content_type :receipt, :content_type => /\Aimage/
  # Validate filename
  validates_attachment_file_name :receipt, :matches => [/png\Z/, /jpe?g\Z/]

Thanks!

Upvotes: 1

Views: 6332

Answers (2)

Rachel9494
Rachel9494

Reputation: 824

This is what I have in my code for a similar project...

validates_attachment_content_type :attachment, content_type: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']

(Obviously you would take the gif out)

Upvotes: 17

NM Pennypacker
NM Pennypacker

Reputation: 6942

Try this:

 validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'application/pdf']

Upvotes: 3

Related Questions