Search code examples
ruby-on-railscloudinary

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


On my website, users can upload documents (thanks to Cloudinary gem) thanks to simple_form_for :

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

and these documents are sent to Stripe thanks to their API. So in my user model, I put :

after_update send_documents_to_stripe, if: :documents_are_upload?

(It just checks if the user has uploaded his documents and if so, the function to send the documents to Stripe is called)

Except that after_update waits for the documents to be entered in the database but it does not wait for the documents to be available on Cloudinary.

So when I try to send the documents to Stripe, I get this error:

Error form rails

Does anyone know how technically I can wait to make sure that Cloudinary has received the images from the user before sending the documents to Stripe?

Thank you very much !


Solution

  • Not sure about the Cloudinary stuff, but you can also do this totally client-side, uploading directly to Stripe: https://jsfiddle.net/thorstripe/bdm3j2rn/

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