jquery - Multiple image upload in a nested form -


i have nested form item model has nested attributes of pictures. code same https://gist.github.com/mhenrixon/978371 i've been trying use jquery file upload shown in railscast 381 i'm able upload 1 image. far can tell looks should , have no idea problem is! below log after trying add multiple images new item

  started post "/admin/items" 127.0.0.1 @ 2013-05-03 13:06:53 +0100 processing admin::itemscontroller#create html   parameters: {"utf8"=>"✓", "authenticity_token"=>"2xp9numsiwmgxrw2llhnurahpdktdw7cf82wjofxqh8=", "item"=>{"name"=>"ddd", "price"=>"", "description"=>"", "stock"=>"", "pictures_attributes"=>{"0"=>{"id"=>"", "attachable_id"=>"", "attachable_type"=>"item", "image"=>#<actiondispatch::http::uploadedfile:0x007fea61735ae8 @headers="content-disposition: form-data; name=\"item[pictures_attributes][0][image]\"; filename=\"image.jpg\"\r\ncontent-type: image/jpeg\r\n", @tempfile=#<file:/var/folders/r3/1gzzfk2964b4tvvndtnr527m0000gn/t/rackmultipart20130503-25456-ynk0x0>, @content_type="image/jpeg", @original_filename="image.jpg">}}}, "button"=>""}   admin load (0.2ms)  select "admins".* "admins" "admins"."id" = 1 limit 1    (0.2ms)  begin transaction   sql (0.7ms)  insert "items" ("created_at", "description", "dimensions", "for_sale", "name", "price", "stock", "updated_at") values (?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", fri, 03 may 2013 12:06:55 utc +00:00], ["description", ""], ["name", "ddd"], ["price", nil], ["stock", nil], ["updated_at", fri, 03 may 2013 12:06:55 utc +00:00]]   sql (0.2ms)  insert "pictures" ("attachable_id", "attachable_type", "created_at", "image", "updated_at") values (?, ?, ?, ?, ?)  [["attachable_id", 47], ["attachable_type", "item"], ["created_at", fri, 03 may 2013 12:06:55 utc +00:00], ["image", "image.jpg"], ["updated_at", fri, 03 may 2013 12:06:55 utc +00:00]]    (3.7ms)  commit transaction redirected http://localhost:3000/admin/items 

use name attribute of file input in array notation

<input type="file" name="myname" /> 

your javascript can like:

if (formdata){     formdata.append("myname[]", files); } 

it should work other way around:

<input type="file" name="myname[]" /> 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -