Commit c4a89182

mo khan <mo@mokhan.ca>
2013-03-06 04:23:48
fix bug in js for the new jquery-file-upload
1 parent 4d72764
Changed files (2)
app
app/controllers/photos_controller.rb
@@ -1,4 +1,5 @@
 class PhotosController < ApplicationController
+
   before_filter :authenticate_user!
   before_filter :find_creation
   #before_filter :find_or_build_photo
@@ -7,7 +8,7 @@ class PhotosController < ApplicationController
     @photos = @creation.photos
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render json: @photos.map { |p| p.to_jq_upload } }
+      format.json { render json: {files: @photos.map { |p| p.to_jq_upload } }.to_json }
     end
   end
 
@@ -33,7 +34,7 @@ class PhotosController < ApplicationController
   def destroy
     @photo = @creation.photos.find(params[:id])
     if @photo.destroy
-      render :json => [@photo.to_jq_upload].to_json
+      render :json => {files: [@photo.to_jq_upload]}.to_json
     else
       render :json => [{:error => "could not remove the photo"}], :status => 304
     end
app/views/photos/_form.html.erb
@@ -6,7 +6,7 @@
     $('#fileupload').each(function () {
       var that = this;
       $.getJSON(this.action, function (result) {
-        if (result && result.length) {
+        if (result) {
           $(that).fileupload('option', 'done').call(that, null, {result: result});
         }
       });