views:

69

answers:

1

I'm trying to figure out which of these parameters contains an uploaded file. This code works

  params[:upload].each do | uploaded_image |
    if (uploaded_image[1] != "")
      # do something with uploaded_image[1];
    end
  end

but my way of moving through the parameters (with the [1], for instance) seems wrong. What's the right way to do this?

+1  A: 

You will be getting the images one at a time using that do loop, so you don't need to index into the array.

Like this:

  params[:upload].each do | uploaded_image |
    unless uploaded_image.blank?
      # do something with uploaded_image[1];
    end
  end

.blank? will cover nil or empty

Brian
Hi and thanks for your answer. This is part of a multipart upload, BTW. The uploaded_image is NEVER blank nor null, but is rather always an array. Just sometimes the 1 is "".
Yar