2017-07-28 79 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回答。