如何在继续控制器操作 after_update 之前等待 Rails 服务响应?

How to wait for Rails service response before continuing controller action after_update?

在我的网站上,用户可以上传文档(感谢 Cloudinary gem)感谢 simple_form_for :

<%= f.cl_image_upload(:ids, allowed_formats: %w(jpg jpeg png)) %>

并且由于 API,这些文档被发送到 Stripe。 所以在我的用户模型中,我输入:

after_update send_documents_to_stripe, if: :documents_are_upload?

(它只是检查用户是否已经上传了他的文件,如果是,则调用将文件发送到 Stripe 的函数)

除了 after_update 等待文档输入数据库但不等待文档在 Cloudinary 上可用。

因此,当我尝试将文档发送到 Stripe 时,出现此错误:

Error form rails

有谁知道在将文档发送到 Stripe 之前,我在技术上如何等待以确保 Cloudinary 已收到用户的图像?

非常感谢!

不确定 Cloudinary 的内容,但您也可以完全在客户端执行此操作,直接上传到 Stripe:https://jsfiddle.net/thorstripe/bdm3j2rn/

console.log("Code because I linked a JSFiddle...");

您可以尝试使用 after_save 而不是 after_update