I'd like to upload multiple pictures using the great jQuery File Upload in my Rails App.
So I followed the Railscasts about it:
But I don't understand why nothing is happening when I try to upload multiple pictures, either using drag and drop or by clicking on "Add files...".
Each picture is saved normally when I push the "submit" button.
Please, could you help me? I'm really stuck.
Many thanks!
application.js ```
//= require jquery
//= require jquery_ujs
//= require jquery-fileupload/basic
//= require housings
housings.coffee
$(document).ready( ->
jQuery ->
file = $('fileupload').fileupload
console.log(file)
)
housings/_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 > index
@picture = Picture.new(housing_id: @user.housings.first.id)
Don't know if this can help anyone but I ended up implementing another javascript tool, Dropzone.
I thought it would be better because FileUpload looks quite old now and I had a headache trying to make it work.
Dropzone works perfectly fine with Rails and looks gorgeous. As a reference, I followed this tutorial.