Forum: Ruby on Rails Posting multiple files - how to set up params correctly

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-03-30 01:47

I have a page where I am allowing the user to specify multiple image
files that are related to one HTML document.

I want to end up with an array of image files that I can then assign
into an array within the controller.

I'm trying to set up my file_field correctly but am having trouble.

I'm not clear on how "the multiple input tags with the same name turning
into an array of parameters" thing works?

I've tried:

<%= file_field('document', 'image[]') %>
<%= file_field('document[]', 'image[]') %>

and when I do debug(params), I never see more than one image in the
"document" hash.

What am I doing wrong here?

Can one use the file_field helper to generate multiple file selection
elements successfully?


Here is my form:

<%= form_tag( { :action => 'upload_images' },
              { :multipart => 'true' } )%>

<% for image in images do %>
      <%= image.path.split('/').last[0..39] %>:
      <% if ((! image.path.nil?) && (image.path.length > 40)) %>
         <%= h("...") %>
      <% end %>
      <%= file_field('document', 'image') %>
<% end %>

  <%= submit_tag "Upload Images" %>

<%= end_form_tag %>

This topic is locked and can not be replied to.