Rails 5: 附件上传后自动提交

Rails 5: Attachinary auto submit after upload

我在 Heroku 上有一个应用程序,我在其中使用 attachinary 将照片上传到 Cloudinary。我想知道在附件上传完成后是否有某种方法或后备方法可以自动提交表单。有人可以帮我解决这个问题吗?

谢谢!

基于 attachinary's document, the gem has a jQuery plugin that based on the jQuery Fileupload plugin,因此您可以随时向 jQuery Fileupload 的事件添加事件处理程序来控制您的业务需求。

jQuery Uploadfile 在 wiki - Callback Options 提供了一个事件列表,因此我认为您可以这样做:

$("#your-upload-input").bind("fileuploaddone", function _doSubmit (event, data) {
  $("#your-form").submit();
})

此外,您可以在 attachinary.js.coffee 查看 attachinary 如何与该插件协作的方式,我们可以看到 gem 使用类似的方式使用上面的代码片段。

希望您能找到合适的方式来满足您的需求