# How do i update an image with Attachment\_Fu?

**URL:** <https://www.ruby-forum.com/t/how-do-i-update-an-image-with-attachment-fu/122818>\
**Category:** Rails\
**Created:** [December 12, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/how-do-i-update-an-image-with-attachment-fu/122818 "2007-12-12T15:44:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [December 12, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/how-do-i-update-an-image-with-attachment-fu/122818/1 "2007-12-12T15:44:37Z")

</div>

Hi, making the switchover from the file\_upload plugin to the pretty  
awesome Attachment\_Fu plugin to handle all my image uploads,

so far going good, but stuck on two things?

Any ideas how i can basically update an image & delete an image ?

can’t seem to find any good examples anywhere,

appreciate it,

John.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [December 12, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/how-do-i-update-an-image-with-attachment-fu/122818/2 "2007-12-12T18:20:39Z")

</div>

it should support User.update\_attributes(params[:user])

where user.rb has the has\_attachment in the model and inside  
params[:user]  
is an “uploaded\_data” file field.

Adam

On Dec 12, 2007 9:44 AM, John G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [December 12, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/how-do-i-update-an-image-with-attachment-fu/122818/3 "2007-12-12T18:50:20Z")

</div>

Thanks for that,

here’s my working [delete] button on the show page

\<%= button\_to “Delete Photo”, :action =\> “destroy”, :id =\> @image %\>

and my destroy method…

def destroy  
Image.find(params[:id]).destroy  
redirect\_to :action =\> ‘list’  
end

and here’s the [edit] page…

\<% form\_for(:image, :url =\> {:id =\> @image, :action =\> “update” }, :html  
=\> { :multipart =\> true }) do |f| -%\>

Replace Photo:  
\<%= image\_tag @image.public\_filename(:thumb) %\>  
with \<%= f.file\_field :uploaded\_data %\>

\<%= f.submit 'Save Changes' %\> or \<%= button\_to\_function "Go Back", "window.location='/image/show/#{@image.id}'" %\>

\<% end -%\>

and the method…

def edit  
@image = Image.find(params[:id])  
end

def update  
@image = Image.find(params[:id])  
if @image.update\_attributes(params[:image])  
flash[:notice] = ‘Photo was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @image  
else  
flash[:notice] = ‘Something awful just happend!’  
render :action =\> ‘edit’  
end  
end

all work, just thought i should post them, so glad i got that out of the  
way, thanks AD
