2017-07-28 84 views
0

我嘗試從選擇框中選擇文件夾,並從罰款上傳作爲參數發送請求。但發送null。我的代碼低於Rails罰款上傳選擇文件夾從選擇框

//haml codes 
    - path = "#{Rails.root}/public/templates/custom/" 
    - folders = Dir["#{path}*"] 
    %select#selected_path.form-control{name: 'folder'} 
     %option{disabled: "disabled", selected: "selected"} Select 
     - folders.each do |folder| 
     %option{value: "#{Rails.root + folder}"} 
      - if File.directory? folder 
      = folder 

對於js代碼

$('#fine-uploader-gallery').fineUploader({ 
    template: 'qq-template-gallery', 
    request: { 
     endpoint: '/admin/files/upload', 
     params: { 
      authenticity_token: "<%= form_authenticity_token %>", 
      // gecici path eklendi 
      selected_path: $('#selected_path').change(function() { 
      alert($('#selected_path option:selected').val()); 
      $('#selected_path option:selected').val() 
      }) 

     } 
    } 
}); 

但上述selected_pa​​th PARAMS給我的錯誤。從js "selected_path"=>"[object HTMLSelectElement]"返回錯誤,不是路徑。我該如何解決這個問題? 預先感謝您

回答

0

添加到HAML,平變化

%select#selected_path.form-control{name: 'folder', :onchange => "go()"} 

對於JS也

$('#fine-uploader-gallery').fineUploader({ 
template: 'qq-template-gallery', 
request: { 
    endpoint: '/admin/files/upload', 
    params: { 
     authenticity_token: "<%= form_authenticity_token %>", 
     // gecici path eklendi 
     selected_path: function go() { 
       var x = document.getElementById('selected_path'); 
       alert(x.value); 
       return x.value; 
     } 
     } 

    } 
}); 

解決的問題。 我引用自https://stackoverflow.com/a/11171135/3239403回答。