You can also try moving out the file upload part to another form, to be handled after the first form is submitted and valid: basically, a two step form, the second step being just the file upload.
On Nov 14, 2:52 pm, "Rob Kaufman" <[EMAIL PROTECTED]> wrote: > Hi Glenn, > In my experiance this is something that is truely borked. Different > browsers report the path differently on the client side, and they all > open the file themselves to send the data and the original file name > up. Other than a flash uploader, you just don't have a good way to > repopulate that data. I've done two things in the past to work around > this (alright three, but I already said flash). > > 1) Upload the file and store it, if the form doesn't validate, push > back the form with the file upload not editable. I hide the asset id > in the form on the second view and display the uploaded file name as a > non editable field. This works except that they can't change the file > and if the file has validations this wont work. > > 2) Client side (JS) validations that run. This way you only send the > file up if the data is good and you can tell them whats wrong with out > reloading the page. The other advantage is if the file upload is big > or slow you won't loose the users attention before showing them whats > wrong with the form. > > Best Of Luck, > Rob > > On Fri, Nov 14, 2008 at 2:18 PM, Glenn Little <[EMAIL PROTECTED]> wrote: > > > By the way, I just found a file_data method called original_path. > > This is what is used to generate original_filename. But bummer, > > in my case, original_path is already just the basename. > > > Also, there is a method called "path". But it turns out the object > > the controller is working with is an UploadedTempFile, and the path() > > method gives you a path to /tmp/blah on the server. > > > Is there a "best practice" on this situation that I may be unaware of? > > > -glenn > > > Glenn Little wrote: > >> Does anyone know of a clean way to pass file upload field data > >> to a rails controller and back to an edit form? > > >> The problem is this: user fills out a (possibly lengthy) form, > >> then submits. If the form does not validate, we give them > >> back the form with most values filled in. But I don't know > >> how to re-seed the file upload fields. Among the problems > >> are that they seem to treated/interpreted differently on the > >> client side, depending on browser and OS. Rails never (reliably > >> anyway) gets to see the actual file path that is the usual > >> content of a file upload field. I think the problem is that > >> it's not really well defined what the "content" of a file upload > >> field is. Is it the data stream? Is it the file path? > >> How is this situation usually (simply) dealt with? > > >> Thanks! > > >> -glenn > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
