【问题标题】:How to wait for Rails service response before continuing controller action after_update?如何在继续控制器操作 after_update 之前等待 Rails 服务响应?
【发布时间】:2021-08-06 11:40:18
【问题描述】:

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

<%= 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

有谁知道我在技术上可以等待以确保 Cloudinary 已收到用户的图像,然后再将文档发送到 Stripe?

非常感谢!

【问题讨论】:

    标签: ruby-on-rails cloudinary


    【解决方案1】:

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

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

    【讨论】:

    • 你好 floatLomas!非常感谢您的帮助它工作得很好!我还有一个问题,我想将这个文档关联到一个已连接的帐户,但是当我添加这个时:data.append('stripe_account', stripe_account_id); 我收到一个错误,invalid params。你知道我该怎么做吗?谢谢!
    • 您得到的确切完整错误是什么?
    【解决方案2】:

    您可以尝试使用after_save 代替after_update。

    【讨论】:

    • 你好丹尼尔,谢谢你的回答,但它不起作用:/
    猜你喜欢
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2020-01-18
    • 2014-07-12
    • 2016-04-02
    • 2012-11-17
    相关资源
    最近更新 更多