I am updating the properties of two models with one model.
begin user.transaction user.update_attributes! (Params [: Users]) @ board.update_attributes! (Params [: Board]) ActiveRecord Rescue :: record unauthorized termination end When user @update_attributes generates an error, the transaction is stopped and the error message is shown in the view .
However, I want to try updating two users and @bird and get error message for both so that the user can fix all their mistakes once.
How can I do this?
Thank you very much earlier.
You can do the following:
User.transaction do @ User.update_attributes (Params [: Users]) @ Board.update_addresses (param [: board]) ActiveRecord :: Increase rollback unless @ user.valid? & Amp; & Amp; @ Board.valid? End will ensure that both update feature methods are run so that you can receive error messages for both objects. If an object is invalid, any changes will not remain in the database.
Comments
Post a Comment