no validates_attachment_file_name when upgrading to Paperclip 4.1 from 3.5

时光总嘲笑我的痴心妄想 提交于 2019-12-05 19:49:05

You can read about the provided validators here:

https://github.com/thoughtbot/paperclip#validations

The included validators are:

  • AttachmentContentTypeValidator
  • AttachmentPresenceValidator
  • AttachmentSizeValidator

They can be used in either of these ways:

# New style:
validates_with AttachmentPresenceValidator, :attributes => :avatar

# Old style:
validates_attachment_presence :avatar

UPDATE ...

If you read further down the link I've given above you'll get to a section on Security Validations (Thanks Kirti Thorat):

https://github.com/thoughtbot/paperclip#security-validations

They give an example on how to validate the filename format:

# Validate filename
validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/]

From your code snippet it looks like your validation should work as-is.

However, I've never seen paperclip used with this syntax:

has_merchants_attached_file ...

Perhaps that's the source of your issues? You would usually use the following to attach files to your model:

has_attached_file :pdf ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!