有没有人有关于使用嵌套属性让 jQuery 文件上传插件与 Rails 一起使用的建议/示例?
我的模型“has_many”附件并接受必要的嵌套属性。我想让它与 jQuery 文件上传一起使用,但还没有找到任何好的例子来帮助我开始。
有没有人取得了这样的成就并能够提供一些指导?
Thanks.
我已成功将其设置为在编辑带有嵌套附件的模型时工作。
创建新模型时,同样的情况是不可能的 - 至少目前由于回形针的原因不可能。
你必须设置一些我发现的 jQuery 文件上传选项here https://github.com/blueimp/jQuery-File-Upload/wiki/Options.
你应该打电话fileUploadUI()
在整个表单上,并将文件输入包装元素设置为dropZone
。你还应该设置url
, fieldName
and formData
因此。
这是我的 JS 的样子(简化):
var $file_upload_form = $("form")
var attachable_id = $file_upload_form.attr("id").match(/_(\d*)$/)[1]
var attachable_type = $file_upload_form.attr("id").match(/edit_(\w*)_\d*$/)[1]
$($file_upload_form).fileUploadUI({
url : '/admin/attachments',
fieldName : "attachment[data]",
formData : [
{
name : 'attachment[attachable_id]',
value : attachable_id
},
{
name : 'attachment[attachable_type]',
value : attachable_type
}
],
dropZone : $('#attachments_dropzone'),
uploadTable : $('#upload_files'),
downloadTable : $('#download_files'),
buildUploadRow : function (files, index) {
var file = files[index];
return $('<tr><td>' + file.name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<button class="ui-state-default ui-corner-all" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/button><\/td><\/tr>');
},
buildDownloadRow: function (file) {
return $('<tr><td><img alt="Photo" width="40" height="40" src="' + file.pic_path + '">' + file.name + '<\/td><\/tr>');
}
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)