How to upload multiple images with file_column + rmagick

how to upload multiple images with file_column + rmagick in one form?

I have done this before using file_column, but have since switched to
attachment_fu. The process should be about the same though. First
off, these links will probably help alot.

They both deal with mootools, to make multiple image uploads a bit
snazzier rather than limiting to so many files per form (or littering
your page with a mess of file fields). If you don’t want to use the
snazzy javascripts, then just create your fields and name them
something like ‘attachments[]’ so that the files get pushed into an
array that rails can use like ‘params[:attachments]’

As for the controller, mine looks like this (again I’m using
attachment_fu, but it should be identical)

def create
@picture =[:picture])
@pictures =

unsaved_pictures = []
saved_pictures = []
params[:attachments] ||= []
params[:attachments].each do |file|
  @picture ={:uploaded_data => file}) unless

file == “”
unsaved_pictures << @picture.filename unless
saved_pictures << @picture.filename if

if saved_pictures.blank?
  flash[:error] = "No Pictures were added."
  if saved_pictures.size < 2
    flash[:notice] = "Picture was successfully added.

flash[:notice] = “Pictures were successfully added.
(#{saved_pictures.join(', ')})”

unless unsaved_pictures.blank?
  if unsaved_pictures.size < 2
    flash[:error] = "File was not added. (#{unsaved_pictures[0]})"
    flash[:error] = "Files were not added.

(#{unsaved_pictures.join(', ')})"

respond_to do |format|
  format.html { redirect_to(item_pictures_url) }


The first to lines should be familiar, then I create empty arrays,
saved_pictures and unsaved_pictures so that I can report stuff back to
the user later. Then I iterate through the attachments making sure
the file field wasn’t empty ( I probably should have used file.empty?
instead of file == “” there). If the picture wasn’t saved I store the
name into my unsaved_pictures array, if it was I store the filename in
saved_puctures array. Then I just use flash to send out notices and
errors depending on what was/wasn’t saved and proper pluralization.

Hope this helps get you going in the right direction.

On a side note if anyone has any suggestions on where I can make this
code better, please do tell me :smiley: The method is a bit beefy and there
are singular/plural flash notices doesn’t seem to dry.

Also has anyone used Paperclip for file attachments yet? If so, how is

On Mar 28, 11:59 pm, Shih T. [email protected]