Clearing a file_column-type field


#1

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
anything.

I tried doing an update_attribute to “”, but I got an error from
file_column:

(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
‘multipart/form-data’.)

Yeah, newbie… :wink:

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

Thanks.

jt


#2

This works for me:

ModelName.find(your_parameters_here).update_attribute
:your_image_column_name, nil

doppler


#3

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
@user.save

Gokhan A.
www.sylow.net


#4

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.

jt