Forum: Ruby on Rails original filename doesn't display in 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.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-17 11:20
(Received via mailing list)
In my item upload view I have:

<%= file_field 'item', 'file' %>


and in my Item model:

def file
	@file
	#@file.original_filename # <- also tried this
end

def file=(file)
	@file=file
end


And if the upload bails because of errors (and renders the same page),
all other fields
(text_field, text_area, etc.) retain their inputted values, but the file
field is blank. Any idea
what the problem is?

I'm using this tutorial as a guide:
http://manuals.rubyonrails.com/read/chapter/79

thanks
csn



__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
5ceea097a3b29cb6a5da6705926410f4?d=identicon&s=25 gerret.apelt (Guest)
on 2005-11-17 11:44
(Received via mailing list)
Have a look at the approach taken by Sebastian Kanthak in his
file_column plugin [1]. When a file upload form had errors and needs
to be re-displayed, he uses a hidden field to reference the file that
had been previously uploaded to the server.

The 'value' attribute of a form "file" input represents only the name
of the file, not the file's content [2] [3]. My guess is that not all
browsers will actually upload a file when you haven't explicitly
selected it with the file input's browse dialog (?). It does work in
Firefox though.

Gerret

[1] http://www.kanthak.net/opensource/file_column/
[2] http://www.cs.tut.fi/~jkorpela/forms/file.html
[3] http://www.faqs.org/rfcs/rfc1867.html
This topic is locked and can not be replied to.