ruby - Rails 4 - Creating associated model during update of another model -
I am using rogue gem to make an example of a model in steps (step 1, step 2, etc.) ) On the third step, however, I need to make an API call to collect some data and store it in the example of another model (this will be one: related to other models). What I am thinking is that how do I communicate with this API and store information, while I am still in the process of creating the first model. Is this a good design pattern? Or should I deal with API information in some other way?
My idea is that I can redirect the form to make API calls and I can redirect back to the fourth step after dealing with the API.
Is there a specific design of rail to deal with third party APIs?
No, this is not a good design pattern, but sometimes there is no way around it It is that
-
Everything is covered by a single database transaction, and that, as I understand from your question, that is the case. Your objects are connected to the "relation to relations" connection, so they can be saved at a time (when "guardian" object is saved, "children" will be saved at one time). There is no other, unrelated object in it, so there is no need to create a separate transaction for this action.
-
The second is that you have enough error handling With everything covered. It is your own responsibility: make sure that when the third party is made to the call, you are ready to catch the error, and the worse case, roll back the whole transaction
Therefore, to summarize: No this is not a good practice, but the train gives you the tools to "keep it clean"
Comments
Post a Comment