Reputation: 3988
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:
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/'[email protected]_s+'/photos/new'}
and in my 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.
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
Upvotes: 3
Views: 1264
Reputation: 3988
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
Upvotes: 4