# Remove file\_column image in a form?

**URL:** <https://www.ruby-forum.com/t/remove-file-column-image-in-a-form/122695>\
**Category:** Rails\
**Created:** [December 10, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/remove-file-column-image-in-a-form/122695 "2007-12-10T22:21:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xguardiola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/13edae/32.png) [@xguardiola](https://www.ruby-forum.com/u/xguardiola)\
**Post date:** [December 10, 2007, 10:21pm UTC](https://www.ruby-forum.com/t/remove-file-column-image-in-a-form/122695/1 "2007-12-10T22:21:26Z")

</div>

Hi all,  
I’ve got the following problem. I’ve got a form for a Project object.  
Three of the fields are images that are attributes of the Projecte  
object. I use the file\_column plugin to upload them.

\<% form\_tag ({action =\> ‘create’}, :multipart =\> true do %\>  
.  
.  
\<%= file\_column\_field ‘project’, ‘image’ %\>  
.  
.  
\<% end %\>

The thing is that I want to let the user delete an image he might have  
uploaded before he presses the submit button. Is that possible? For what  
I’ve read, the way to delete the image is to set projecte.image=nil  
before a project.save (which is done when the form is submitted). How  
could I let the user do that before the submit? Any ideas would be  
appreciated!  
Thanks in advance,

Xavi.

---

<div class="post-metadata">

**Author:** ![xguardiola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/13edae/32.png) [@xguardiola](https://www.ruby-forum.com/u/xguardiola)\
**Post date:** [December 11, 2007, 1:31am UTC](https://www.ruby-forum.com/t/remove-file-column-image-in-a-form/122695/2 "2007-12-11T01:31:45Z")

</div>

Xavier Guardiola wrote:

> The thing is that I want to let the user delete an image he might have  
> uploaded before he presses the submit button. Is that possible? For what  
> I’ve read, the way to delete the image is to set projecte.image=nil  
> before a project.save (which is done when the form is submitted). How  
> could I let the user do that before the submit? Any ideas would be  
> appreciated!

I generally put a checkbox on the form (a normal checkbox not tied to  
the model or anything. I.E.

\<%= check\_box\_tag ‘remove\_image’ %\>

Then in my “update” action I put the following:

@project = Project.find params[:id]  
@project.attributes = params[:project]  
@project.image = nil if params[:remove\_image]  
if @project.save  
flash[:notice] = “Project #{@project} sucessfully updated”  
redirect\_to projects\_path  
else  
render :action =\> 'edit  
end

So basically we just have an extra param to flag the image for removal.

Eric

---

<div class="post-metadata">

**Author:** ![xguardiola](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/13edae/32.png) [@xguardiola](https://www.ruby-forum.com/u/xguardiola)\
**Post date:** [December 11, 2007, 11:07am UTC](https://www.ruby-forum.com/t/remove-file-column-image-in-a-form/122695/3 "2007-12-11T11:07:33Z")

</div>

Thanks Eric! that worked!  
Cheers,

Xavi.
