Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Fail to send multiple files

#1997

When i tried to upload few images to server on new Rails 2.3.0 RC i found that some of my params just disappears. Here is what i have in controller:

def new

@hotel = Hotel.new
(1..8).each { @hotel.hotel_images.build }

end

def create

p params # Just for testing purposes

end

And here is my simple form:

<% form_for @hotel, :html => {:multipart => true} do |f| %>

<% f.fields_for :hotel_images do |hi| %>
  <%= hi.file_field :image %>
  <br />
<% end %

<% end %>

Sending empty form results in such params[:hotel] hash:

{ "hotel_images_attributes"=>{

 "new_1"=>{"image"=>nil},
 "new_2"=>{"image"=>nil}, 
 "new_3"=>{"image"=>nil}, 
 "new_4"=>{"image"=>nil}, 
 "new_5"=>{"image"=>nil}, 
 "new_6"=>{"image"=>nil}, 
 "new_7"=>{"image"=>nil}, 
 "new_8"=>{"image"=>nil}

} }

When i put one file in "slot" one named hotel[hotel_images_attributes][new_1][image] my params[:hotel][hotel_images_attributes] hash looks like:

"hotel_images_attributes"=>{ "new_1"=>{"image"=>#<File:/tmp/RackMultipart.22893.7>}, "new_3"=>{"image"=>nil}, "new_4"=>{"image"=>nil}, "new_5"=>{"image"=>nil}, "new_6"=>{"image"=>nil}, "new_7"=>{"image"=>nil}, "new_8"=>{"image"=>nil}}

so, somewhere new_2 key with values disappears. What interesting - when i put two files, on "new_1" and "new_2", then after upload there is no "new_3" and "new_4" and so on.. So, multiple files upload is impossible, because only one file is sent at all. But - funny thing is that when i put files on "new_1", "new_3" and for example "new_5" - whole bulk of files is sent properly, but ofcourse in resulting params hash there is no keys named "new_2" and "new_4" - so if there had been files they wouldn't have been available after transfer.

I tested this on Rails 2.3.0 RC using mongrel and thin on both - firefox and opera.

Reported by phlawski · February 17th, 2009 @ 02:32 PM

State: duplicate
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • Milestone cleared.
    • Assigned user set to josh
    • State changed from new to duplicate

    This was know problem on the RC1 release. Please test again on master.

    February 17th, 2009 @ 03:58 PM

  2. phlawski
    phlawski

    I just tried it on rails edge (rake rails:freeze:edge) and there is the same behaviour.

    February 17th, 2009 @ 08:31 PM

  3. phlawski
    phlawski

    Oh, nope. Sorry, it's my fault. I didn't restart rails after freeze. Everything works properly/

    February 17th, 2009 @ 08:43 PM