Forum: Ruby on Rails Clearing a file_column-type field

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John T. (Guest)
on 2006-01-23 04:27
So I am now able to set/upload an image to my app using file_column,
with a little bit of a change to the code.

I can change the image using an Edit page, but I'm trying to figure out
what to do if the user wants to remove the image. I tried adding a
Remove Image link in my list, but I'm not sure what to do in the
remove_image method in my controller. I tried setting the 'image' value
to ''; I tried using update_attribute to set to '' and neither did
anything. The SQL update command that was logged just showed it
replacing the records values with the same data - ie. not changing

I tried doing an update_attribute to "", but I got an error from

(Do not know how to handle a string with value 'nothing' that was passed
to a file_column. Check if the form's encoding has been set to

Yeah, newbie... ;)

(And I haven't even added a second relationship table to my app
yet..figured this would be the easy part.)


David R. (Guest)
on 2006-01-23 07:22
(Received via mailing list)
This works for me:

:your_image_column_name, nil

Gokhan A. (Guest)
on 2006-01-23 09:26
David R. wrote:
> This works for me:
> ModelName.find(your_parameters_here).update_attribute
> :your_image_column_name, nil
> doppler

@user = User.find(1)
@user.your_file_column = nil

Gokhan A.
John T. (Guest)
on 2006-01-23 09:48
Thanks! Those both worked.

I had something like that, but was getting an error - which actually
turned out to be in my "show" method - it was trying to display the
image tag, but the field was nil. Now it checks and works.

This topic is locked and can not be replied to.