jschwindt/rjcrop — Issue #4: Image gets cached, so doesn't change after crop
Author: jgarber
Created: 2011-10-27 16:53:28+00:00
State: open

In production I ran into an issue where the user would see the *before* image after they had cropped because cropping didn't update Rails' asset id and so the browser thought it was the same image. Rather than eliminating caching for that directory in Apache or trying to tap into ActionView and sweep the asset id cache, I thought it might be better to let paperclip change the filename based on the crop settings.

In Jcropper:

self.interpolates(:crop_suffix) do |attachment, style|
target = attachment.instance
if target && (style != :original) && target.cropping?
"-#{target.crop_x.to_i}#{target.crop_y.to_i}#{target.crop_h.to_i}#{target.crop_w.to_i}"
else
""
end
end

And in your model, add on these parameters:

:url => "/system/:attachment/:id/:style/:basename:crop_suffix.:extension",
:path => ":rails_root/public/system/:attachment/:id/:style/:basename:crop_suffix.:extension"

At least that worked for me with Paperclip 2.4.5 and Rails 3. Sharing it here in case others run into the same problem.