我正在为rails 4应用程序创建直接上传表单。我跟着this tutorial并修改它以满足我的需要。一切都进展顺利,除了我上传文件“]]>”
后现在收到这篇奇怪的文章文章
以下是相关文件:
_upload_form.html.haml
= s3_uploader_form callback_url: uploads_url,
id: "s3_uploader",
callback_param: "upload[direct_upload_url]",
expiration: 24.hours.from_now.utc.iso8601,
max_file_size: 100.megabytes do
#file_field_container
.wrapper
= file_field_tag :file, multiple: true, class: "btn btn-primary"
= button_tag "Select file", class: 'btn btn-primary btn-lg'
#uploads_container
%script#template-upload{type: "text/x-tmpl"}
:cdata
<div id="upload_{%=o.unique_id%}" class="upload">
<h5>{%=o.name%}</h5>
<div class="progress progress-striped active"><div class="bar" style="width: 0%"> </div></div>
</div>
上传/ create.js.erb
<% if @upload.persisted? %>
$('#upload_<%=params[:unique_id]%>').hide();
<% else %>
$('#upload_<%=params[:unique_id]%> div.progress').removeClass('active progress-striped').addClass('progress-danger');
<% end %>
uploads.js
$(function() {
$('#s3_uploader').S3Uploader(
{
remove_completed_progress_bar: false,
progress_bar_target: $('#uploads_container')
}
);
$('#s3_uploader').bind('s3_upload_failed', function(e, content) {
return alert(content.filename + ' failed to upload');
});
});
答案 0 :(得分:0)
我最终将视图转换为erb 。这解决了这个问题。
然而,我仍然想知道为什么它不能用于haml ......