How can I restrict Paperclip to only accept images?

前端 未结 2 1697
刺人心
刺人心 2021-02-07 20:24

How can I restrict Paperclip to only accept images? I\'m using Amazon S3 for storage if that\'s relevant. Thanks for reading.

2条回答
  •  难免孤独
    2021-02-07 20:32

    Paperclip has validation methods like validates_attachment_presence, validates_attachment_content_type, and validates_attachment_size.

    So all you need to do is pass mime types of images you'd like to have as attachments:

    validates_attachment_content_type 'image/png', 'image/jpg'
    

提交回复
热议问题