2013-12-17 4 views
0

Я пытаюсь загрузить несколько фотографий с помощью jquery-fileupload-railsJQuery загрузки файлов ActionController :: UnknownFormat

Вот мой Javascript для делать это:

<script type="text/javascript" charset="utf-8"> 
    $(function() { 
     // Initialize the jQuery File Upload widget: 
     $('#fileupload').fileupload({ 
     paramName: 'album_picture[picture]' 
     }); 
     // 
     // Load existing files: 
     $.getJSON($('#fileupload').prop('action'), function (files) { 
     var fu = $('#fileupload').data('blueimpFileupload'), 
      template; 
     fu._adjustMaxNumberOfFiles(-files.length); 
     console.log(files); 
     template = fu._renderDownload(files) 
      .appendTo($('#fileupload .files')); 
     // Force reflow: 
     fu._reflow = fu._transition && template.length && 
      template[0].offsetWidth; 
     template.addClass('in'); 
     $('#loading').remove(); 
     }); 

    }); 
</script> 

Вот заголовки запроса:

POST /album_pictures HTTP/1.1 
Host: 127.0.0.1:3000 
Connection: keep-alive 
Content-Length: 98937 
Accept: undefined 
Origin: http://127.0.0.1:3000 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFhpKR7ztl9s9QWAZ 
Referer: http://127.0.0.1:3000/album_pictures/new/3 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: he-IL,he;q=0.8,en-US;q=0.6,en;q=0.4 

Вот параметры запроса:

{"utf8"=>"✓", "authenticity_token"=>"xXkbJNMVVNy3SocUJKKHHts0RO8PEP8aGqw8C+dlaKw=", "album_picture"=>{"album_id"=>"3", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007fac660e8c28 @tempfile=#<Tempfile:/var/folders/_7/jc0746b936q9b3q3lsf7xj7m0000gn/T/RackMultipart20131217-71351-1csiua>, @original_filename="gall1_big5.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"album_picture[picture]\"; filename=\"gall1_big5.jpg\"\r\nContent-Type: image/jpeg\r\n">}} 

я получаю следующее:

ActionController::UnknownFormat (ActionController::UnknownFormat): 
    app/controllers/album_pictures_controller.rb:49:in `create' 

respond_to do |format| 

Вот мой код контроллера:

def create 
    @album_picture = AlbumPicture.new(album_picture_params) 

    respond_to do |format| 
     if @album_picture.save 
     format.html { 
      render :json => [@album_picture.to_jq_upload].to_json, 
      :content_type => 'text/html', 
      :layout => false 
     } 
     format.json { render json: {files: [@album_picture.to_jq_upload]}, status: :created, location: @album_picture } 
     else 
     format.html { render action: "new" } 
     format.json { render json: @album_picture.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

ответ

0

Проблема заключается в контроллере ваш respond_to блок не отформатирован должным образом. Отправьте этот код, если вы хотите получить более конкретный ответ.

+1

Вы должны были прокомментировать это, но в любом случае я добавил код контроллера. – Danpe

Смежные вопросы