【发布时间】:2014-02-14 05:01:59
【问题描述】:
我正在为我的 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');
});
});
【问题讨论】:
-
您是否尝试过在源代码中搜索该字符串?
-
这看起来像
<![CDATA[ ... ]]>的结尾部分 -
我已尝试搜索该字符串,但无济于事。还有凯文,我在我的 haml 中使用了一个 cdata 过滤器(参见 _upload_form)。也许我的语法关闭了?我用谷歌搜索了haml+cdata,也无济于事。
标签: javascript jquery ruby-on-rails file-upload ruby-on-rails-4