Forum: Ruby on Rails file_column :: changing image with object.update

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bf1e5a140a444bdc5011185bba3a1ed3?d=identicon&s=25 Shark Fin Soup (Guest)
on 2006-02-16 08:43
(Received via mailing list)
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
Bf1e5a140a444bdc5011185bba3a1ed3?d=identicon&s=25 Shark Fin Soup (Guest)
on 2006-02-17 10:20
(Received via mailing list)
So no taker on this question so far?

Sharkie
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-02-18 17:38
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 Soup wrote:
> So no taker on this question so far?
>
> Sharkie
Bf1e5a140a444bdc5011185bba3a1ed3?d=identicon&s=25 Shark Fin Soup (Guest)
on 2006-02-19 09:10
(Received via mailing list)
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
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-02-20 06:17
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 Soup 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
This topic is locked and can not be replied to.