0

Looks like it's a known issue but i'm not able to find any solution nor any dirty fix to make it working. The thing is i'm not able to remove attachments uploaded using Carrierwave plugin.

I'm using a special form field called :remove_avatar which should remove a avatar file and clear avatar column but the only thing it does is deleting the file, the file reference in avatar column still exists.

I was trying to remove it in any possible way but without a luck.

update_attributes

using u.update_attributes( :avatar => "" ) is not removing the reference

save()

u = User.find(int)
u.avatar = ""
u.save

is also not removing the reference

remove_avatar = true

u.remove_avatar = true
u.save

not working

remove_avatar!

u.remove_avatar!
u.save

not working

f.check_box :remove_avatar

not working

By 'not working' i mean that the file is removed from filesystem but the reference persists.

Cany you please provide me ANY tip i can use to make it working again? It can be something dirty, this bug shown a day before my deadline and i feel quite desperate. Thanks in advance.

Ruby: 1.8.7
Rails: 3.2.6
Carrierwave: master branch from git repo

mbajur
  • 4,406
  • 5
  • 49
  • 79

1 Answers1

3

According to this thread, you can probably manage this by using update_column instead of update_attribute, and then (for reasons not currently clear to me), really forcing a reload of the in-memory object (instead of just calling reload on it):

u = User.where('avatar is not null').last # Get a user with an avatar
u.update_column(:avatar, nil) # Use update_column to avoid callbacks
u = User.where(:id => u).first # Force a reload of the object. No, u.reload doesn't work. No, I don't know why.

When I do this in my console, u.avatar is finally blank. My version info, in case this doesn't work for you: Ruby 1.9.3, Rails 3.2.2, PostgreSQL 9.2, CarrierWave 0.5.7

Community
  • 1
  • 1
MrTheWalrus
  • 9,670
  • 2
  • 42
  • 66