No validates_attachment_file_name when upgrading to Paperclip 4.1 of 3.5

We have a code that looks like a clip on a paper clip:

has_merchants_attached_file :pdf,
    storage:          :s3, 
    s3_credentials:   Mbc::DataStore.s3_credentials,
    s3_permissions:   :private,
    path:             ":identifier_template.pdf",
    bucket:           Mbc::DataStore.forms_and_templates_bucket_name


  validates_attachment_file_name :pdf, :matches => [/pdf\Z/]

What generates the error:

undefined method `validates_attachment_file_name' for #<Class:0x007fba67d25fe0>

Interestingly, when we lower the class to 3.5, we are faced with the same problem.

The controller that generates this:

def index
   @fidelity_templates = FidelityTemplate.order("identifier asc").all
end

Additionally:

def has_merchants_attached_file(attribute, options={})
  if Rails.env.test? || Rails.env.development?
     has_attached_file attribute,
     path: "paperclip_attachments/#{options[:path]}"
  else
    has_attached_file attribute, options
  end
end

Any thoughts on what might be causing this?

+3
source share
1 answer

Here you can read about the provided validators:

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

Validators included:

  • AttachmentContentTypeValidator
  • AttachmentPresenceValidator
  • AttachmentSizeValidator

They can be used in one of the following ways:

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

# Old style:
validates_attachment_presence :avatar

UPDATE ...

, , " " ( Kirti Thorat):

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

, :

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

, .

, :

has_merchants_attached_file ...

, ? :

has_attached_file :pdf ...
+2

All Articles