# Attatchment fu - NO DELETE ability

**URL:** <https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844>\
**Category:** Rails\
**Created:** [December 4, 2008, 11:56am UTC](https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844 "2008-12-04T11:56:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![denver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@denver](https://www.ruby-forum.com/u/denver)\
**Post date:** [December 4, 2008, 11:56am UTC](https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844/1 "2008-12-04T11:56:50Z")

</div>

Hi Guys,

I have installed the attatchment\_fu plugin and got it working so can  
upload images to my application. I used Mike C.'s Weblog as a  
guide. [http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu](http://clarkware.com/cgi/blosxom/2007/02/24#FileUploadFu).

I can upload images no problem but there seems to be no way of  
deleting the images from the articles, and I have been scratching my  
head all morning as to how to accomplish this.

* * *

## module Admin::ArticlesHelper def article\_image\_for(article) if article.article\_image article\_img = article.article\_image.public\_filename link\_to image\_tag(article\_img), article.article\_image.public\_filename #else #image\_tag(“blank-image.png”) end end end

Articles \_form.html.erb

\<%= article\_image\_for(@article) %\>

 \<% else %\>

You can upload an image for this article below

 \<% end %\>

\<%= label :article, :article\_image %\>  
\<%= file\_field\_tag :article\_image\_file %\>

Acceptable file formats include JPEG,  
PNG or GIF upto 500kb in size and 500px in width

--------------------------------------------------------------------------------------

class CreateArticleImages \< ActiveRecord::Migration  
def self.up  
create\_table :article\_images do |t|  
t.integer :article\_id, :parent\_id, :size, :width, :height  
t.string :content\_type, :filename, :thumbnail  
t.timestamps  
end  
end

def self.down  
drop\_table :article\_images  
end  
end

---

<div class="post-metadata">

**Author:** ![denver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@denver](https://www.ruby-forum.com/u/denver)\
**Post date:** [December 4, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844/2 "2008-12-04T12:11:32Z")

</div>

I created a button on the form page

\<%= button\_to “Delete Image”, { :action =\>  
“delete\_article\_image”, :article\_image\_id =\>  
@article.article\_image.id } %\>

and in my articles controller I created the following method;

def delete\_article\_image  
@article\_image = ArticleImage.find(params[:article\_image\_id])  
@article\_image.destroy

```
respond_to do |format|
  format.html { redirect_to(admin_articles_url) }
  format.xml { head :ok }
end

```

end

This code does not throw up any errors, but it does not delete the  
record in the article\_images table

Any help would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![denver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@denver](https://www.ruby-forum.com/u/denver)\
**Post date:** [December 4, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844/3 "2008-12-04T13:29:18Z")

</div>

Ive also tried

def delete\_article\_image  
@article = Article.find(params[:id])  
@article\_image = @article.article\_image  
@article\_image.destroy

```
respond_to do |format|
  format.html { redirect_to(admin_articles_url) }
  format.xml { head :ok }
end

```

end

but it still does not remove the entry from the database… please  
help guys

---

<div class="post-metadata">

**Author:** ![denver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@denver](https://www.ruby-forum.com/u/denver)\
**Post date:** [December 4, 2008, 1:58pm UTC](https://www.ruby-forum.com/t/attatchment-fu-no-delete-ability/154844/4 "2008-12-04T13:58:45Z")

</div>

dont worry. i fixed the problem. it was because the button was inside  
a \_form page and so the variables were not passed across
