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.