views:

46

answers:

1

Alright this one's tricky - don't shy off!

I've setup a multi-file uploader with Rails 3 + paperclip + Ajax Upload (http://valums.com/ajax-upload/)

My controller is as follows (which works):

  def upload
    @photoalbum = PhotoAlbum.create
    @photo = @photoalbum.photos.create({ :photo => params[:file], :title =>  params[:filename], :description => "Uploaded on #{Date.today.strftime("%b %d, %Y")}" })

    respond_to do |format|
      format.json
    end
  end

The big issue here. is that if a User uploads 3 files, they are all going to seperate albums. Rails uploads the 3 files, and each file has it's own uniquely added album.

That's bad. I need all the files uploaded in a batch to go to it's own album..

Any thoughts on how to solve for this?

In the AJAX upload it is possible to pass a param. I thought about passing an album ID, problem is that would lead to a lot of blank albums, as the user doesn't always upload photos.

Geniuses wanted! thank you

+1  A: 

I agree with the commenter before. You should post your params hash and a little more code, but... One way to approach it would be to try and use the ajax callback (jQuery passes back a callback on each ajax call, I think most other libraries also to the same) to upload the next photo in the sequence. I would imagine that it would go something like this:

  1. User uploads 3 photos.
  2. Rails processes the upload of the first one and then sends a callback looking for more. This callback would include the album id of the album it just uploaded the first photo to. If there were no photos uploaded there would be no call to the upload action and hence no album created.
  3. Rails uploads the second image using the callback album id to know where to put the second photo.
  4. Process repeats until all photos are uploaded.

Like I said though, it would be a lot easier to give a more comprehensive answer if you posted more code.

erskingardner