I'm preforming an ajax file upload in Rails with jQuery fileupload. The first upload works fine, but when I try a consecutive upload I get a server error saying:
我正在用jQuery fileupload在Rails中预装一个ajax文件上传。第一次上传效果很好,但是当我尝试连续上传时,我收到一个服务器错误提示:
Unexpected error while processing request: expected Array (gotRack::Utils::KeySpaceConstrainedParams) for param `photos'
/home/uriklar/.rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/utils.rb:114:in `normalize_params'
This is how my upload process is working: In an Apartment form I have a nested form for photos
这就是我上传过程的工作方式:在公寓表单中,我有一个用于照片的嵌套表单
= f.simple_fields_for Photo.new do |photo|
= photo.file_field :photo, label: false, class: 'photo_upload_input', multiple: true, name: "photos[]", data: {url: '/apartments/'+@apartment.id.to_s+'/photos/new'}
and in my javascript:
在我的javascript:
$('.photo_upload_input').fileupload();
The first file upload sends me to the correct action (Photos#update) and saves the photos correctly. It even works for multiple files.. It calls the action separately for each file.
第一个文件上载将我发送到正确的操作(Photos#update)并正确保存照片。它甚至适用于多个文件。它分别为每个文件调用操作。
def update
@apartment = Apartment.find(params[:apartment_id])
@photo = @apartment.photos.create(photo: params[:photos][0])
end
The problem is, when I try to upload a second round of photos I get the error written above. It doesn't even hit the controller... What does this error mean? Any help would be greatly appreciated! Thanks
问题是,当我尝试上传第二轮的照片时,我得到了上面写的错误。它甚至没有击中控制器……这个错误是什么意思?如有任何帮助,我们将不胜感激!谢谢
1 个解决方案
#1
4
After digging deep inside the Rack code and understanding very little of it, I decided to do change: name = "photos[]"
to name="photos"
(in the file_field input) and now it's all working! Not really sure why... but that's my solution
在深入挖掘了机架代码并了解了很少的代码之后,我决定进行更改:name=“photos[]”到name=“photos”(在file_field输入中),现在一切正常了!不知道为什么…但是这是我的解决方案
#1
4
After digging deep inside the Rack code and understanding very little of it, I decided to do change: name = "photos[]"
to name="photos"
(in the file_field input) and now it's all working! Not really sure why... but that's my solution
在深入挖掘了机架代码并了解了很少的代码之后,我决定进行更改:name=“photos[]”到name=“photos”(在file_field输入中),现在一切正常了!不知道为什么…但是这是我的解决方案