I am trying to modify the image upload example in the Agile book to handle mtltiple files. I have been playing with it for a while now, but no luck. Do I have to create a loop, and do each file seperate, or can I just save an array of files? How can I set up my form and controller to handle this? Will I have to modify the model? -- Posted via http://www.ruby-forum.com/.
Hi, Scott I have stuggled with the same problem. Ultimately I have resorted to file_column, a plugin that can handle multiple files. You can find it at http://www.kanthak.net/opensource/file_column/ . To handle multiple files, you should put something like the following in your model: class Entry < ActiveRecord::Base file_column :image1 file_column :image2 file_column :image3 end Kind regards, Nick scottnj wrote:> I am trying to modify the image upload example in the Agile book to > handle mtltiple files. > > I have been playing with it for a while now, but no luck. > > Do I have to create a loop, and do each file seperate, or can I just > save an array of files? > > How can I set up my form and controller to handle this? Will I have to > modify the model?-- Posted via http://www.ruby-forum.com/.
Nick Snels <nick.snels@...> writes:> > Hi, > > Scott I have stuggled with the same problem. Ultimately I have resorted > to file_column, a plugin that can handle multiple files. You can find it > at http://www.kanthak.net/opensource/file_column/ . > > To handle multiple files, you should put something like the following in > your model: > > class Entry < ActiveRecord::Base > file_column :image1 > file_column :image2 > file_column :image3 > end > > Kind regards, > > Nick > > scottnj wrote: > > I am trying to modify the image upload example in the Agile book to > > handle mtltiple files. > > > > I have been playing with it for a while now, but no luck. > > > > Do I have to create a loop, and do each file seperate, or can I just > > save an array of files? > > > > How can I set up my form and controller to handle this? Will I have to > > modify the model? >I used the following js to create a dynamic array of files and then loop through the array. (stickman''s multiple upload javascript) http://snipurl.com/ko7u then use something like: @files = [] params[:file].each {|k,v| @files[k.to_i] = v if v.size>0} for file in @files do stuff end Works a treat. Note- I found that for some reason an empty file element seemed to be created which screwed everything up so added v.size>0. Hope this is of interest. Graham.
g.arrowsmith wrote:> I used the following js to create a dynamic array of files and then loop > through > the array. (stickman''s multiple upload javascript) > http://snipurl.com/ko7uI saw this and am considering it, but I need something to work if javascript is disabled. -- Posted via http://www.ruby-forum.com/.