carrierwaveuploader / carrierwave

Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks
https://github.com/carrierwaveuploader/carrierwave
8.78k stars 1.66k forks source link

not updating images when old and new filename are the same #2680

Closed Complaex-Makandra closed 1 year ago

Complaex-Makandra commented 1 year ago

When updating an image in Carrierwave with another image that shares the exact filename the association between the model and the image breaks and the image will no longer be shown.

The reason for this in my understanding is that the name in the store dir will morph into ...(2) but the reference in the model will still point on the file without the new assigned number. poster(2)

What am I doing wrong?

A simple solution would be (reference):

 def filename
    if File.exist?(File.join(store_dir, file.filename)) && path != (File.join(store_dir, original_filename))
      @name ||= "#{File.basename(original_filename, '.*')}_#{Digest::MD5.hexdigest(original_filename).from(25)}"
      "#{@name}.#{file.extension}"
    else
      original_filename
    end
  end

But I dont think this should be necessary.

Im using Ubuntu: Linux 5.14.0-1059-oem x86_64

Complaex-Makandra commented 1 year ago

Sorry I didn't see the other issue which seems to be exactly the same #2678