Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use paperclip before_post_process with multiple attachments?

I'm trying to add a 2nd attachment to a model with Paperclip. I'm using a simple thumbnail processor like:

has_attached_file :attachment, :styles => { :thumb => "100x100>" }
has_attached_file :attachment2, :styles => { :thumb => "100x100>" }

I want it not to create thumbnails for non-image types like:

before_post_process :is_image?
def is_image?
  !(File.extname(attachment_file_name) =~ /\A.jpe?g|pjpeg|gif|x-png|png\Z/i).nil?
end

How do I do that for the 2nd attachment? The problem being the reference to attachment_file_name which would need to be attachment2_file_name for the 2nd one.

like image 401
Mark Robinson Avatar asked Oct 25 '25 10:10

Mark Robinson


1 Answers

It seems it's possible to write:

before_attachment_post_process :is_image?
before_attachment2_post_process :is_image2?
like image 100
Mark Robinson Avatar answered Oct 26 '25 22:10

Mark Robinson