thoughtbot/paperclip — Issue #691: Processing of files shouldn't happen when assigning the file
Author: iwiznia
Created: 2011-12-29 16:39:42+00:00
State: open

I just run into a problem using paperclip and learned that the processors are run when you set the file in the model, I was expecting for them to run while saving (on a before/after_save or before/after_validation calbacks).
The benefits are that If model doesn't validate, the processing of the attachments aren't run. This is a good thing since the model won't be saved anyway, processing the attachment is a cpu intensive work, so we save cpu power.
I came across this problem in a different way, I have a custom processor that takes info from a field in a related model and prints that inside the image, when I do:
user.photos.build(params[photo])
User has_many _photos, photo is the model using paperclip and belongs_to :user. When I call that method, the make method of the processor is run, but the photo instance doesn't have the user set.

I expected the post processors (like the docs call them) to be run when the model gets saved (and of course after the validations occur).
Not sure if I explained this well, would be happy to clarify if it's not understandable.