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

Carrierwave 1.1.0 deletes images when setting the property to the same value on an ActiveRecord model. #2196

Closed
RocketPuppy opened this issue Jun 13, 2017 · 3 comments

Comments

@RocketPuppy
Copy link

This is a little tough to pin down a minimal example for, so I'm going to do my best here:

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  version :thumb do
    process resize_to_fill: [256, 256]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def store_dir
    "avatars"
  end

  def filename
    File.extname(super) if super
  end
end

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
  validates :avatar file_size: { less_than 2.megabytes }
end

Ok, so normal operation all seems to work fine. Uploading a file will set the avatar property to the path, and uploading a different file will change the path. However, if I do something like user.update(avatar: u[:avatar]), the image is deleted and the avatar property stays the same. This could easily happen if, for example, a form was prefilled with the existing values and those values were all passed into a call like user.update(form_params).

It seems to me like this is normally desirable behavior to remove old images when new ones are uploaded. However in this case there isn't a new image to upload and the value doesn't change.

Note that I did not see this behavior on version 0.10.0, only on 1.1.0.

@llpereiras
Copy link

llpereiras commented Aug 7, 2017

I tried to do this with version 1.1.0 and 1.0.0, and this doesn't work.

e = Equipe.find(1)
e.update(e.attributes)
e.imagem.url
nil

This bug are confirmed in this 2 versions.

on version 0.11.2 and 0.10.0 it's work's properly.

@ivane-gkomarteli
Copy link

ivane-gkomarteli commented Sep 27, 2019

Any update on this issue?

I face the same problem on version 1.0.0 to 1.3.1.

@mshibuya
Copy link
Member

#2401 has changed this behavior.

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

4 participants