# Image upload with attachment\_fu

**URL:** <https://www.ruby-forum.com/t/image-upload-with-attachment-fu/137411>\
**Category:** Rails\
**Created:** [May 12, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/image-upload-with-attachment-fu/137411 "2008-05-12T22:41:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattmcswain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@mattmcswain](https://www.ruby-forum.com/u/mattmcswain)\
**Post date:** [May 12, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/image-upload-with-attachment-fu/137411/1 "2008-05-12T22:41:32Z")

</div>

I want to be able to edit the uploaded images from attachment\_fu. In my  
view I do something like this:

**Cover**  
 \<%= f.file\_field :cover %\>

and then in my controller, I do something like

@book = Book.new(params[:book].except(:author\_ids, :cover))  
if !params[:book][:cover].instance\_of? String  
@cover = Cover.create!(:uploaded\_data =\> params[:book][:cover],  
:book\_id =\> @book.id)  
end

I just wanted to know if this is the best way to do this or if there is  
something I am missing

---

<div class="post-metadata">

**Author:** ![mattmcswain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@mattmcswain](https://www.ruby-forum.com/u/mattmcswain)\
**Post date:** [May 12, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/image-upload-with-attachment-fu/137411/2 "2008-05-12T23:05:30Z")

</div>

You’ll want to save the book first so that @book.id will exist.

Other than that, I’m not really sure what you mean about being able to  
edit the images.

Are you getting a particular error?

On May 12, 3:41 pm, Matt M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mattmcswain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@mattmcswain](https://www.ruby-forum.com/u/mattmcswain)\
**Post date:** [May 12, 2008, 11:09pm UTC](https://www.ruby-forum.com/t/image-upload-with-attachment-fu/137411/3 "2008-05-12T23:09:25Z")

</div>

JDevine wrote:

> You’ll want to save the book first so that @book.id will exist.
> 
> Other than that, I’m not really sure what you mean about being able to  
> edit the images.
> 
> Are you getting a particular error?
> 
> On May 12, 3:41 pm, Matt M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Sorry, I forgot to mention that I am saving. I am not getting any  
errors, I just wasn’t sure if there was a better way.

What I mean by editing the images is I want to be able to create the  
Book with or without an image and update the image at any time.
