Forum: Ruby on Rails attatchment fu - NO DELETE ability

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
792ae44d201909299282ab8dd5028546?d=identicon&s=25 denver (Guest)
on 2008-12-04 11:56
(Received via mailing list)
Hi Guys,

I have installed the attatchment_fu plugin and got it working so can
upload images to my application. I used Mike Clark'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
<p>
  <%= article_image_for(@article) %>

</p>
  <% else %>
<p>
  You can upload an image for this article below
</p>
  <% end %>

  <%= label :article, :article_image %>
  <%= file_field_tag :article_image_file %>
  <br />

  <span class="supported-files">Acceptable file formats include JPEG,
PNG or GIF upto 500kb in size and 500px in width</span>
</p>
--------------------------------------------------------------------------------------

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
792ae44d201909299282ab8dd5028546?d=identicon&s=25 denver (Guest)
on 2008-12-04 12:11
(Received via mailing list)
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
792ae44d201909299282ab8dd5028546?d=identicon&s=25 denver (Guest)
on 2008-12-04 13:29
(Received via mailing list)
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
792ae44d201909299282ab8dd5028546?d=identicon&s=25 denver (Guest)
on 2008-12-04 13:58
(Received via mailing list)
dont worry. i fixed the problem. it was because the button was inside
a  _form page and so the variables were not passed across
This topic is locked and can not be replied to.