I definitely think this would be a very useful recipe. Uploading a CSV file with the first line that includes the field names is something everyone needs. Not requiring additional plugins would be useful IMHO.
-O On Mon, Jul 19, 2010 at 2:16 PM, kevinpfromnm <[email protected]>wrote: > You might want to make a virtual file field on the model that handles > the processing. > > def file_data=(file_data) > @file_data = file_data > file_data.original_filename =~ /^(.*)\.([^.]*)$/ > self.ext = ($2 || 'unknown').downcase > self.orig_filename = ($1 || file_data.original_filename).gsub(/[^a- > zA-Z0-9_.-]/,'_') > end > > after_save :process > > private > > def process > if @file_data > create_directory > save_fullsize > create_thumbnail > @file_data = nil > end > end > > def save_fullsize > File.open(fullsize_path, 'wb') do |file| > file.puts @file_data.read > end > end > > That's an example of what I did on an older rails project (before > paperclip was the easy fix for this). It's obviously not the complete > model but should give you the idea of how you can do it. > > On Jul 19, 9:46 am, Henry Baragar <[email protected]> > wrote: > > On July 17, 2010 09:17:54 pm Matt Jones wrote: > > > > > > > > > On Jul 16, 2010, at 12:57 PM, Henry Baragar wrote: > > > > Hello, > > > > I need to provide a web page in a Hobo application for uploading a > > > > file that contains data for generating a whole bunch of records. The > > > > file is discards after the data is processed. > > > > What is the Hobo way of doing this? > > > > > > • Create a Webform and use the Rails file_field_tag? > > > > • Create a LifeCycle and use the Rails file_field_tag? > > > > • Do it the Rails way? > > > > > I'm not sure there's an official "Hobo way" to do this; the Rails > > > uploaded file stuff will definitely come into play at some point. > > > > > One approach I haven't seen get much coverage, though, is a two-step > > > approach. First, you upload the file (pick your favorite plugin - > > > Paperclip, etc) and create a corresponding database record. Then, the > > > user has a link in the UI to "process" the file, which can take more > > > parameters *and* has the luxury of having the to-be-processed file > > > handy. > > > > Way too sophisticated for my needs. > > > > Is/should this be a recipe? > > > > Thanks, > > Henry > > > > > In my use case, it was absolutely necessary to have that access, since > > > the "process" step allows the user to control the mapping of columns > > > in the uploaded CSV to columns in the model. (They were uploading > > > files provided by *their* clients, and didn't want to hassle with > > > moving stuff around manually). The other win was that "failed" rows > > > from the import could be dumped into a new file record, so they could > > > be corrected (if they didn't pass validation) or just ignored (if > > > somebody left useless nearly-blank rows, etc). > > > > > --Matt Jones > > > > -- > > Henry Baragar > > Instantiated Software > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<hobousers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/hobousers?hl=en. > > -- - Owen Owen Dall, Chief Systems Architect Barquin International Cell: 410-991-0811 -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
