Forum: Ruby on Rails Handling file uploads & mixing class and instance vars

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.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 CSN (Guest)
on 2005-12-23 03:28
(Received via mailing list)
Hey Everybody,

This is the only way I've been able to get my file
upload to work:

class Item < ActiveRecord::Base

  def file=(upload)
    @file=upload
  end

  def after_create
    File.open("public/items/#{self.id}.jpg", "w") {
|f| f.write(@file.read) }
  end

end

The upload form has "file_field 'item', 'file', ...".
I've tried using self.file (causes a stack error), and
@id (empty). It just feels wrong mixing class and
instance vars ;). Am I missing something?

Thanks,
csn





__________________________________
Yahoo! for Good - Make a difference this year.
http://brand.yahoo.com/cybergivingweek2005/
A4b45b0467e28925b5103b50f7d39e5d?d=identicon&s=25 Mark Beattie (Guest)
on 2005-12-23 03:49
(Received via mailing list)
On Friday 23 December 2005 11:27 am, CSN wrote:
> ... Am I missing something?

http://www.kanthak.net/opensource/file_column/index.html

--

Mark Beattie
Easy Schedule Management
http://easy-online-schedule.com
This topic is locked and can not be replied to.