# File\_column :: changing image with object.update

**URL:** <https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101>\
**Category:** Rails\
**Created:** [February 16, 2006, 8:43am UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101 "2006-02-16T08:43:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [February 16, 2006, 8:43am UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101/1 "2006-02-16T08:43:04Z")

</div>

Dear all,

file\_column now works fine with object.save i.e., it updates my  
database field with the correct image file name and places the image  
file into the correct public folder.

However, I cannot get file\_column to work the same way with  
object.update when trying to change image. It only updates my field  
with the image file name. However, the new image is not copied into  
the correct public folder.

Does anyone have an example on how to get this to work?

Thank you,

Shark

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [February 17, 2006, 10:20am UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101/2 "2006-02-17T10:20:05Z")

</div>

So no taker on this question so far?

Sharkie

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [February 18, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101/3 "2006-02-18T17:38:33Z")

</div>

It would help if you posted the relevant snippets from your controller  
and your form code. 😉

Are you using the same form or partial for both the “new” and “edit”  
views?

Under normal circumstances, \<%= file\_column\_field … %\> should work  
fine.

Shark Fin S. wrote:

> So no taker on this question so far?
> 
> Sharkie

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [February 19, 2006, 9:10am UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101/4 "2006-02-19T09:10:33Z")

</div>

Hi Steve,

Form codes for new view:

\<%= start\_form\_tag({:action =\> “process\_submit\_story”, :id =\>  
@story\_entry.id}, :multipart =\> true) %\>  
\<%= file\_column\_field “story\_entry”, “image” %\>

Form codes for edit view:

\<%= start\_form\_tag({:action =\> “process\_admin\_story”, :id =\>  
@story\_entry.id}, :multipart =\> true) %\>  
\<%= file\_column\_field “story\_entry”, “image” %\>

In new controller, which works fine

@story\_entry = StoryEntry.new params[:story\_entry]  
@story\_entry.save

In admin controller, I don’t know how to do this

@story\_entry.stuff = params[:story\_entry][:stuff]  
@story\_entry.update

Sharkie

---

<div class="post-metadata">

**Author:** ![Shark\_Fin\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@Shark\_Fin\_S](https://www.ruby-forum.com/u/Shark_Fin_S)\
**Post date:** [February 20, 2006, 6:17am UTC](https://www.ruby-forum.com/t/file-column-changing-image-with-object-update/69101/5 "2006-02-20T06:17:00Z")

</div>

You don’t have to do anything unusual to handle a :file\_column field in  
the controller. If your varchar field is present in the database table  
and the

```
 :file_column fieldname

```

incantation is present in the model, you’re all set. And since it’s  
working in the process\_submit\_story action (which is essentially what  
the scaffold generates as a “create” action), you’ve got that set up  
right.

I don’t know what you’re doing with that “stuff” method and :stuff  
property in your process\_admin\_story action, though. You should model  
this action on the “update” action generated by scaffolding, e.g.:

def process\_admin\_story  
@story\_entry= StoryEntry.find(params[:id])  
if @story\_entry.update\_attributes(params[:story\_entry])  
flash[:notice] = ‘The story was successfully updated.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘edit’  
end

The key call is the update\_attributes method, which… well… updates  
whatever object attributes are present in the passed parameters, leaves  
other attributes untouched, and then saves the changes.

Hope this helps.

Shark Fin S. wrote:

> Hi Steve,
> 
> Form codes for new view:
> 
> \<%= start\_form\_tag({:action =\> “process\_submit\_story”, :id =\>  
> @story\_entry.id}, :multipart =\> true) %\>  
> \<%= file\_column\_field “story\_entry”, “image” %\>
> 
> Form codes for edit view:
> 
> \<%= start\_form\_tag({:action =\> “process\_admin\_story”, :id =\>  
> @story\_entry.id}, :multipart =\> true) %\>  
> \<%= file\_column\_field “story\_entry”, “image” %\>
> 
> In new controller, which works fine
> 
> @story\_entry = StoryEntry.new params[:story\_entry]  
> @story\_entry.save
> 
> In admin controller, I don’t know how to do this
> 
> @story\_entry.stuff = params[:story\_entry][:stuff]  
> @story\_entry.update
> 
> Sharkie
