Forum: Ruby on Rails problems with file_field

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.
Pingu P. (Guest)
on 2007-01-14 15:51
Hello everyone

My rails app can upload images, and add the image path and name to the
database. But when i use very similar code to edit that entry by
uploading a different picture to replace the original, no changes take
place, can anyone see where i am going wrong?


The form that adds the image (in new.rhtml)
[code=]  <p>Thumbnail <br />
  <%= file_field "product", "thing" %></p>[/code]
The model that handels it
[code=]class Product < ActiveRecord::Base
  belongs_to :department

    def thing=(picture_field)
    self.thumbnail = picture_field.original_filename
    # need 'public' or image_tag in front of images for webrick
    File.open("public/images/#{picture_field.original_filename}", "w") {
|f| f.write(picture_field.read) }
  end

end[/code]
The controller method is the default scaffold generated.

But when i copy the code from the new.rhtml, to edit.rhtml, and i try to
upload an image, nothing happens!!

Anyone have any idea what i have messed up?
This topic is locked and can not be replied to.