# Attachment\_fu: how to remove images?

**URL:** <https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982>\
**Category:** Rails\
**Created:** [February 23, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982 "2008-02-23T18:15:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 23, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982/1 "2008-02-23T18:15:47Z")

</div>

I just used attachment\_fu for the first time, and it works quite well.  
I have a user-model, and each of them has\_one :image (and the images  
belongs\_to :user). I have a question on this though: how can i remove  
images? Whenever i set a new image for a user (a user who already has  
an image), then the table with images gets updated correctly, with the  
user\_id column of the old image set to null, and the new image then  
has the correct user\_id.

What i want is ofcourse to remove the old image (which has no  
references to any user anymore) from the database and the filesystem,  
and the same for the thumbnail that was created with it.

Does attachment\_fu have methods for this?

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 23, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982/2 "2008-02-23T20:29:53Z")

</div>

Peter wrote:

> What i want is ofcourse to remove the old image (which has no  
> references to any user anymore) from the database and the filesystem,  
> and the same for the thumbnail that was created with it.
> 
> Does attachment\_fu have methods for this?

Did you try: user.image.destroy or user.image.delete (bypass  
callbacks?)

hth

ilan

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 23, 2008, 9:03pm UTC](https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982/3 "2008-02-23T21:03:37Z")

</div>

That works quite good. I have the feeling i should’ve known or at  
least tried that 🙂

Thank you!

On Feb 23, 8:29 pm, Ilan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 23, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/attachment-fu-how-to-remove-images/129982/4 "2008-02-23T21:09:49Z")

</div>

Peter wrote:

> That works quite good. I have the feeling i should’ve known or at  
> least tried that 🙂
> 
> Thank you!
> 
> On Feb 23, 8:29 pm, Ilan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

No worries at all, I can’t count the times I got an answer and then  
proceeded to smack my head on the desk!

ilan
