0

我没有运气让 ajax jquery 文件上传与我的应用程序一起使用,我的实现基于 Ryan Bate 的,尽管我使用的是 Paperclip 而不是 Carrierwave http://railscasts.com/episodes/381-jquery-上传文件

在我的控制台中,我收到错误:ReferenceError: file is not defined

如果有帮助,这是空气制动的回溯:

url/assets/styleitems.js?body=1:6 in "HTMLFormElement.$.fileupload.add"
url/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1:490 in "$.Widget._trigger"
url/assets/jquery-fileupload/jquery.fileupload.js?body=1:815 in "File.<anonymous>"
url/assets/jquery.js?body=1:385 in "Function.jQuery.extend.each"
url/assets/jquery-fileupload/jquery.fileupload.js?body=1:805 in "$.widget._onAdd"
url/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1:106 in "null._onAdd"
url/assets/jquery-fileupload/jquery.fileupload.js?body=1:985 in "Object.<anonymous>"
url/assets/jquery.js?body=1:3100 in "fire"
url/assets/jquery.js?body=1:3146 in "Object.self.add"
url/assets/airbrake_shim.js?body=1:77 in "Object.cb.add"

在我的应用程序控制器中,我有其他文件:

//= require jquery-fileupload/basic
//= require jquery-fileupload/vendor/tmpl

我还安装了 jquery-fileupload-rails gem

js.coffee 文件:

 $ ->
  $('#new_styleitem').fileupload
    dataType: "script"
    add: (e, data) ->
      data.context = $(tmpl("template-upload", file))
      $('#new_styleitem').append(data.context)
      data.submit()
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')

形式:

= form_for([@class_object, Styleitem.new], html: {multipart: true}) do |f|
  = f.text_field :styleable_type, type: :hidden, value: @class_object.class.to_s
  = f.number_field :styleable_id, type: :hidden, value: @class_object.id
  = f.number_field :user_id, type: :hidden, value: authority_user.id
  = f.file_field :asset, multiple: true, name: "styleitem[asset]"
  = render partial: 'layouts/drag_and_drop'

布局/拖放的内容

%script{id: "template-upload", type: "text/x-tmpl"}
  .upload
    .progress
      .bar{style: "width: 0%"}

任何想法我做错了什么?

4

1 回答 1

0

我是个白痴,我从咖啡脚本文件中删除了一些我没有使用的代码,我不小心删除了

file = data.files[0]

结案。

于 2014-05-08T21:50:50.473 回答