Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image gets cached, so doesn't change after crop #4

Open
jgarber opened this issue Oct 27, 2011 · 0 comments
Open

Image gets cached, so doesn't change after crop #4

jgarber opened this issue Oct 27, 2011 · 0 comments

Comments

@jgarber
Copy link

jgarber commented Oct 27, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant