Hello all,
I have a working file_column installation on a Document class. I can upload,
download, and delete files with this class with no problem (using the
documents controller).
The problem comes when I try to upload a file from a different controller.
Specifically, I have a URL ³/users/new" that results in this in the form
view:
<%= file_column_field ''document'',
''filename'' %>
or, rendered,
<input id="document_filename_temp"
name="document[filename_temp]"
type="hidden" /><input id="document_filename"
name="document[filename]"
size="30" type="file" />
This is identical to how it''s used and rendered in
"/documents/new".
In the controller for "users/create" (which is called from the form),
I do
exactly what I do in "documents/create":
@document = Document.new(params[:document])
The document object will get created and the row will get saved in the db
table, but there is never a file uploaded. More precisely, the parameters
are always like this:
"document"=>{"filename_temp"=>""}
If I upload the same document from "/documents/new", the params are
like
this:
"document"=>{"filename_temp"=>"",
"filename"=>#<StringIO:0x22c64f8>}
I figure that all the cool stuff happens in the model, so it shouldn''t
matter which controller does the uploading. But, I must be missing
something, probably obvious. Any ideas what''s going on?
-Paul
Are you missing the enctype="multipart/form-data" on the other form? On 12/8/05, Paul Welty <paul.welty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello all, > > I have a working file_column installation on a Document class. I can upload, > download, and delete files with this class with no problem (using the > documents controller). > > The problem comes when I try to upload a file from a different controller. > Specifically, I have a URL ³/users/new" that results in this in the form > view: > > <%= file_column_field ''document'', ''filename'' %> > > or, rendered, > > <input id="document_filename_temp" name="document[filename_temp]" > type="hidden" /><input id="document_filename" name="document[filename]" > size="30" type="file" /> > > This is identical to how it''s used and rendered in "/documents/new". > > In the controller for "users/create" (which is called from the form), I do > exactly what I do in "documents/create": > > @document = Document.new(params[:document]) > > The document object will get created and the row will get saved in the db > table, but there is never a file uploaded. More precisely, the parameters > are always like this: > > "document"=>{"filename_temp"=>""} > > If I upload the same document from "/documents/new", the params are like > this: > > "document"=>{"filename_temp"=>"", "filename"=>#<StringIO:0x22c64f8>} > > I figure that all the cool stuff happens in the model, so it shouldn''t > matter which controller does the uploading. But, I must be missing > something, probably obvious. Any ideas what''s going on? > > -Paul > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
D''oh! You''re right, of course. Color me embarrassed. Thanks! -P On 12/8/05 1:58 PM, "Kyle Maxwell" <kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org> wrote:> Are you missing the enctype="multipart/form-data" on the other form? > > On 12/8/05, Paul Welty <paul.welty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hello all, >> >> I have a working file_column installation on a Document class. I can upload, >> download, and delete files with this class with no problem (using the >> documents controller). >> >> The problem comes when I try to upload a file from a different controller. >> Specifically, I have a URL ³/users/new" that results in this in the form >> view: >> >> <%= file_column_field ''document'', ''filename'' %> >> >> or, rendered, >> >> <input id="document_filename_temp" name="document[filename_temp]" >> type="hidden" /><input id="document_filename" name="document[filename]" >> size="30" type="file" /> >> >> This is identical to how it''s used and rendered in "/documents/new". >> >> In the controller for "users/create" (which is called from the form), I do >> exactly what I do in "documents/create": >> >> @document = Document.new(params[:document]) >> >> The document object will get created and the row will get saved in the db >> table, but there is never a file uploaded. More precisely, the parameters >> are always like this: >> >> "document"=>{"filename_temp"=>""} >> >> If I upload the same document from "/documents/new", the params are like >> this: >> >> "document"=>{"filename_temp"=>"", "filename"=>#<StringIO:0x22c64f8>} >> >> I figure that all the cool stuff happens in the model, so it shouldn''t >> matter which controller does the uploading. But, I must be missing >> something, probably obvious. Any ideas what''s going on? >> >> -Paul >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails