File_column :: changing image with object.update

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

So no taker on this question so far?

Sharkie

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

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

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

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