gpt4 book ai didi

ruby-on-rails - Rails 3 和嵌套 jQuery 文件上传模型

转载 作者:行者123 更新时间:2023-12-01 03:25:41 27 4
gpt4 key购买 nike

有人有关于使用嵌套属性让 jQuery 文件上传插件与 Rails 一起使用的建议/示例吗?

我的模型“has_many”附件并接受必要的嵌套属性。我想让它与 jQuery 文件上传一起使用,但一直无法找到任何好的示例来帮助我开始。

有人取得了这样的成就并能够提供一些指导吗?

谢谢。

最佳答案

我已成功将其设置为在编辑带有嵌套附件的模型时工作。
创建新模型时,这是不可能的 - 至少目前由于回形针的原因不可能。

你必须设置一些我发现的 jQuery 文件上传选项 here .

您应该在整个表单上调用fileUploadUI(),并将文件输入包装元素设置为dropZone。您还应该相应地设置 urlfieldNameformData

这是我的 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>');
}
})

关于ruby-on-rails - Rails 3 和嵌套 jQuery 文件上传模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5533879/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com