我将 gem 'jquery-fileupload-rails' 和 'carrierwave_backgrounder' gem 与 sidekiq 一起使用。下载完成后如何添加重新加载页面?
问题是下载在后台并且页面立即重新加载,而不是在加载图像时
文件上传.js
$(function () {
$('#new_photo').fileupload({
acceptFileTypes: '/(\.|\/)(gif|jpe?g|png)$/i',
dataType: 'html',
add: function (e, data) {
data.context = $('#loading').css({display:"block"}).appendTo('#photos');
data.submit();
},
done: function (e, data) {
data.context.text('Upload finished.');
location.reload();
}
});
});
image_upload.html.erb
<div class="upload" id="new_photo">
<%= form_for([@project, current_user.photos.new]) do |f| %>
<%= file_field_tag :image, multiple: true, name: "photo[image]" %>
<%= link_to 'Save', @project, :class => 'btn btn-success' %>
<% end %>
<div id="loading">
<h4>Loading</h4>
</div>
</div>
<div class="image-upload">
<% @project.photos.each do |photo| %>
<%= image_tag photo.image_url.to_s %>
<p><%= link_to "Delete", project_photo_path(@project, photo), :method => :delete, :class => 'btn' %></p>
<% end %>
</div>