# How to properly upload a file in the same form as a parent model?

**URL:** <https://www.ruby-forum.com/t/how-to-properly-upload-a-file-in-the-same-form-as-a-parent-model/147950>\
**Category:** Rails\
**Created:** [September 7, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/how-to-properly-upload-a-file-in-the-same-form-as-a-parent-model/147950 "2008-09-07T14:25:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [September 7, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/how-to-properly-upload-a-file-in-the-same-form-as-a-parent-model/147950/1 "2008-09-07T14:25:21Z")

</div>

Hi,

let’s say you got a Gallery model that has one (to simplify things a  
bit for now) Image (attachment\_fu model). Gallery has i.e. title and  
description, both fields are required. In the “create new gallery  
form” you can set title, description and upload the image as well.

What to do if the gallery object validation fails? How do you handle  
such situations? Do you create the image anyway, so when user is  
redirected back to the form to fix errors, he doesn’t have to upload  
the image again or do you require them to upload the image again? It’s  
not a big deal if there’s only one image per gallery, but what if  
gallery could have many images and user would have to upload again 10  
images, just to fix the missing title?

Is there an easy solution for such problem (without making “draft”  
objects (like i.e. emails in GMail), or making separate form for  
gallery and images)?
