i have a piece of code which is used to do following things triggered from a controller call.i am using Rails Transaction along with begin/rescue end block to make the below series of code execution more robust.Its as shown below:-
- Save the object
- save the associations and update the attribute value
- send email
- send text message
-
redirect
###in my controller def verify @request=Request.includes(:user).find(params[:id]) @request.transaction do begin if @request.accepted? ##this method will call more 3 methods in the request model @request.send_email_and_sms flash[:success] = "Request is moved to another state" else flash[:error] = "Request was not accepted and couldn't be moved to another state" end rescue flash[:alert] = "There was some internal error.Kindly debug" ensure @request.reload Rails.logger.info "================Making GO AHEAD TOKEN FALSE AND DEACTIVATE VENUE====================#{@request.attributes}===========" redirect_to request_hall_path(@request.user) end end end
`
Is this the correct way to ensure that every piece of code will execute else it will jump on rescue with the flash.alert message.
Is there any other way that i am missing to make this code/logic more full proof and robust.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire