Shark Fin Soup
2006-Feb-16 07:40 UTC
[Rails] 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
Shark Fin Soup
2006-Feb-17 09:17 UTC
[Rails] file_column :: changing image with object.update
So no taker on this question so far? Sharkie On Feb 16, 2006, at 2:38 PM, Shark Fin Soup wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Steve Koppelman
2006-Feb-18 16:38 UTC
[Rails] Re: file_column :: changing image with object.update
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-- Posted via http://www.ruby-forum.com/.
Shark Fin Soup
2006-Feb-19 08:08 UTC
[Rails] Re: file_column :: changing image with object.update
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 On Feb 18, 2006, at 11:38 PM, Steve Koppelman wrote:> 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Steve Koppelman
2006-Feb-20 05:17 UTC
[Rails] Re: Re: file_column :: changing image with object.update
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-- Posted via http://www.ruby-forum.com/.