jQuery FileUpload gem没有初始化

时间:2015-11-03 17:19:07

标签: jquery ruby-on-rails ruby file-upload jquery-fileupload-rails

我想在我的Rails应用程序中使用优秀的jQuery文件上传来上传多张图片。

所以我跟着Railscasts about it

  • 添加jquery-fileupload-rails gem
  • 在我的application.js
  • 中添加一个require
  • 为我的照片创建表单
  • 在名为“housings.coffee”的文件中初始化FileUpload

但我不明白为什么当我尝试上传多张图片时,无论是使用拖放还是点击“添加文件...”都没有发生任何事情。

按下“提交”按钮时,每张图片都会正常保存。

拜托,你能帮帮我吗?我真的被卡住了。

非常感谢!

  

的application.js   ```

//= require jquery
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require housings
  

housings.coffee

$(document).ready( ->
  jQuery ->
    file = $('fileupload').fileupload
    console.log(file)
)
  

座/ _form.html.erb

<%= form_for [@user, @picture], html: { multipart: true, id: 'fileupload'} do |f| %>
      <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
      <div class="row fileupload-buttonbar">
        <div class="span7">
          <!-- The fileinput-button span is used to style the file input field as button -->
          <span class="btn btn-success fileinput-button">
            <i class="icon-plus icon-white"></i>
            <span>Add files...</span>
            <%= f.file_field :image, multiple: true, name: 'picture[image]' %>
          </span>
            <%= f.hidden_field :housing_id, value: @housing.id %>
          <button type="submit" class="btn btn-primary start">
            <i class="icon-upload icon-white"></i>
            <span>Start upload</span>
          </button>
          <button type="reset" class="btn btn-warning cancel">
            <i class="icon-ban-circle icon-white"></i>
            <span>Cancel upload</span>
          </button>
          <!--<button type="button" class="btn btn-danger delete">-->
            <!--<i class="icon-trash icon-white"></i>-->
            <!--<span>Delete</span>-->
          <!--</button>-->
          <input type="checkbox" class="toggle">
        </div>
        <div class="span5">
          <!-- The global progress bar -->
          <div class="progress progress-success progress-striped active fade">
            <div class="bar" style="width:0%;"></div>
          </div>
        </div>
      </div>
      <!-- The loading indicator is shown during image processing -->
      <div class="fileupload-loading"></div>
      <br>
      <!-- The table listing the files available for upload/download -->
      <table class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody>
      </table>
  <% end %>
  

housings_controller.rb&gt;索引

@picture = Picture.new(housing_id: @user.housings.first.id)

1 个答案:

答案 0 :(得分:0)

不知道这是否可以帮助任何人,但我最终实现了另一个javascript工具,Dropzone

我认为它会更好,因为FileUpload现在看起来很老了,我一直在努力让它发挥作用。

Dropzone与Rails完美搭配,外观华丽。 作为参考,我遵循了this tutorial