Question

I'm trying to use the method recreate_versions! but I'm using the method from the wiki to create unique filenames. The problem is that when I run recreate_versions! it changes the filenames but it doesn't update them on the mounted object itself. How could I refresh these URL's?

Was it helpful?

Solution

Here is what worked for me. It uses the filename if it already exists. So they don't change when you recreate_versions!

def filename
  if original_filename
    if model && model.read_attribute(:avatar).present? #or whatever you call your column
      model.read_attribute(:avatar)
    else
      # create new filename however you're doing it
    end
  end
end

OTHER TIPS

A solution that works when dealing with caching is to save the mounted object after recreating versions:

Example:

avatar.image.recreate_versions!
avatar.save!

This way you can keep using unique filenames even when recreating versions and properly handle caching.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top