Attatchment fu - NO DELETE ability


#1

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.

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


#2

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


#3

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


#4

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