Carrierwave with Dropzone JS. Is it possible to use these with nested attributes?

痞子三分冷 提交于 2019-12-06 00:19:52

Finally found a way to make dropzone.js working with rails nested attributes. You have to edit dropzone.js to set the format of rails nested attribute array for multiple attachments.

Dropzone.prototype._getParamName = function(n) {
  if (typeof this.options.paramName === "function") {
    return this.options.paramName(n);
  } else {
    return "" + this.options.paramName1 + (this.options.uploadMultiple ? "[" + n + "]" : "") + this.options.paramName2 + "";
  }
};

Then inside dropzone initialization javascript initialize both params:

Dropzone.options.newTicket =
        clickable:'#previews'
        previewsContainer: "#previews"
        dictDefaultMessage: "Drop files here or click to select files"
        autoProcessQueue: false
        uploadMultiple: true
        paramName1: "ticket[attachments_attributes]"
        paramName2: "[file]"
        parallelUploads: 5
        maxFiles: 5
        addRemoveLinks: true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!