# Attachment\_fu file upload optional in 'new' view?

**URL:** <https://www.ruby-forum.com/t/attachment-fu-file-upload-optional-in-new-view/91394>\
**Category:** Rails\
**Created:** [April 8, 2007, 7:13am UTC](https://www.ruby-forum.com/t/attachment-fu-file-upload-optional-in-new-view/91394 "2007-04-08T07:13:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 8, 2007, 7:13am UTC](https://www.ruby-forum.com/t/attachment-fu-file-upload-optional-in-new-view/91394/1 "2007-04-08T07:13:56Z")

</div>

In my ‘new’ view for an Item object, the user can upload a picture of  
the item. How can I make the upload optional (while creating the new  
item)? I’m using REST and this is a portion of what my controller  
looks like to make it Mandatory to upload an image:

respond\_to do |format|  
if @item.save and @photo.save

Now if I remove the @photo.save no image will be created (even if it  
is valid).

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 8, 2007, 12:12pm UTC](https://www.ruby-forum.com/t/attachment-fu-file-upload-optional-in-new-view/91394/2 "2007-04-08T12:12:12Z")

</div>

Okay I figured it out. I assigned the @photo to @item:  
@item.photo = @photo

then:  
respond\_to do |format|  
if @item.save

Attachment\_fu is a great plugin!
