# Deleting images with attachment\_fu

**URL:** <https://www.ruby-forum.com/t/deleting-images-with-attachment-fu/162166>\
**Category:** Rails\
**Created:** [March 6, 2009, 11:44am UTC](https://www.ruby-forum.com/t/deleting-images-with-attachment-fu/162166 "2009-03-06T11:44:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flychunjae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@flychunjae](https://www.ruby-forum.com/u/flychunjae)\
**Post date:** [March 6, 2009, 11:44am UTC](https://www.ruby-forum.com/t/deleting-images-with-attachment-fu/162166/1 "2009-03-06T11:44:59Z")

</div>

Hi

I’m trying to delete a user’s profile image that was uploaded with  
attachment\_fu directly to storage, without going to the view of the  
Photo controller.

Basically the model is set up so

user has many photos  
photos belong to user

```
@user = User.find(params[:id])
@photo = Photo.new(params[:photo])

```

there is no problem viewing the photos but i’m trying to have a link  
next to the picture in the view of the User controller which would  
delete the photo.

i tried:

def destroyphoto  
@user = User.find(params[:id])  
@photo = @user.photos.find(params[:id])  
@photo.destroy  
end

with:

\<%= link\_to “delete”, destroyphoto\_user\_url, :method =\> :delete %\>

but i get the:

Couldn’t find Photo with ID=1 AND (`photos`.user\_id = 1)

the photo’s id isn’t 1 and it’s actually many because of the original  
image and the thumbnails.

any ideas?

---

<div class="post-metadata">

**Author:** ![flychunjae](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@flychunjae](https://www.ruby-forum.com/u/flychunjae)\
**Post date:** [March 6, 2009, 3:12pm UTC](https://www.ruby-forum.com/t/deleting-images-with-attachment-fu/162166/2 "2009-03-06T15:12:02Z")

</div>

> any ideas?

You shouldn’t be passing in params[:id] in your photos find…  
params[:id] is your users\_id, not a photo\_id.

have you tried just

@photos = @user.photos

Then you’ll have to iterate across all the photos returned to delete  
each one.
