Ad

Finding Uploads In Parameters On Submit In Rails

- 1 answer

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?

Ad

Answer

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

Ad
source: stackoverflow.com
Ad