[Posted again because of lack of helpful subject line. A thousand apologies.] Hello, New to Rails, pretty new to Ruby. Running rails 0.10.1. I must have broken something, but damned if I can figure out what I did! I have a simple form that uploads a file to an action, using post and multipart, yada yada: <%= form_tag({:action=>''process_tes''}, :multipart => true)%> <input type="file" name="tes_file" /> <input type="submit" name="Upload" /> </form> But--by the time it gets to the action, it''s become a string. I can''t call any of the CGI.rb type methods on it, such as .read or .original_filename. In essence, it appears that it has already been converted to the original filename. The line in development.log looks like this: Processing TesfilesController#process_tes (for 10.2.2.173 at Wed Mar 16 10:17:13 CST 2005) Parameters: {"tes_file"=>"thesaurus.csv", "action"=>"process_tes", "Upload"=>"", "controller"=>"tesfiles"} Now, at one point this was working. Instead of seeing the filename "thesaurus.csv" I would see a tmpfile object reference. My problem is that I am utterly clueless about what might be happening that takes a simple file upload POST Http request and extracting the filename, but not actually accepting the file upload. Also I can''t imagine what I did to break this. Any help''s appreciated! Thanks to the Rails community for putting together such an elegant product. Thanks, Jonathan ----------------------------------- Jonathan Broad jonathan-CXfrjL/NW9NJgPAc0y4pFg@public.gmane.org
On Mar 16, 2005, at 11:34 AM, Jonathan Broad wrote:> [Posted again because of lack of helpful subject line. A thousand > apologies.] > > Hello, > > New to Rails, pretty new to Ruby. Running rails 0.10.1. > > I must have broken something, but damned if I can figure out what I > did! I have a simple form that uploads a file to an action, using > post and multipart, yada yada: > > <%= form_tag({:action=>''process_tes''}, :multipart => true)%> > <input type="file" name="tes_file" /> > <input type="submit" name="Upload" /> > </form> > > But--by the time it gets to the action, it''s become a string.I was having problems with a file upload form and I think a bug was introduced in the form_tag helper in 0.10.1. View the source of your page... Does it have ''multipart="true"'' as an attribute of your form tag, instead of correctly turning the :multipart option into ''enctype="multipart/form-data"''? If so, I have two solutions. One, don''t use the form_tag helper - just write the form tag by hand to get the file upload to work. <form action="/mycontroller/process_tes" enctype="multipart/form-data" method="post"> The second solution is to fix the bug in the form_tag helper. For my installation, I edited "/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.1/lib/action_view/ helpers/form_tag_helper.rb", and changed lines 16-19 to this: if html_options["multipart"] # used to be :multipart html_options["enctype"] = "multipart/form-data" html_options.delete("multipart") # used to be :multipart end You need to restart your web server to load the new code. This fix is already in svn, so things should be good in the next release... Zach
That was it exactly. Thanks Zach--I looked at everything a dozen times, but never suspected the way the form was rendered! I moved machines and upgraded rails by accident when I dloaded the gem, which is why it had worked on 0.10. I suspected a bug, but assumed it was in the processing machinery, not the rendering machinery. Cheers, Jonathan On Mar 16, 2005, at 2:28 PM, Zach Thompson wrote:> On Mar 16, 2005, at 11:34 AM, Jonathan Broad wrote: > >> [Posted again because of lack of helpful subject line. A thousand >> apologies.] >> >> Hello, >> >> New to Rails, pretty new to Ruby. Running rails 0.10.1. >> >> I must have broken something, but damned if I can figure out what I >> did! I have a simple form that uploads a file to an action, using >> post and multipart, yada yada: >> >> <%= form_tag({:action=>''process_tes''}, :multipart => true)%> >> <input type="file" name="tes_file" /> >> <input type="submit" name="Upload" /> >> </form> >> >> But--by the time it gets to the action, it''s become a string. > > I was having problems with a file upload form and I think a bug was > introduced in the form_tag helper in 0.10.1. View the source of your > page... Does it have ''multipart="true"'' as an attribute of your form > tag, instead of correctly turning the :multipart option into > ''enctype="multipart/form-data"''? > > If so, I have two solutions. One, don''t use the form_tag helper - > just write the form tag by hand to get the file upload to work. > > <form action="/mycontroller/process_tes" enctype="multipart/form-data" > method="post"> > > The second solution is to fix the bug in the form_tag helper. For my > installation, I edited > "/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.1/lib/action_view/ > helpers/form_tag_helper.rb", and changed lines 16-19 to this: > > if html_options["multipart"] # used to be :multipart > html_options["enctype"] = "multipart/form-data" > html_options.delete("multipart") # used to be :multipart > end > > You need to restart your web server to load the new code. > > This fix is already in svn, so things should be good in the next > release... > > Zach > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >----------------------------------- Jonathan Broad jonathan-CXfrjL/NW9NJgPAc0y4pFg@public.gmane.org