nr: #1 dodano: 2016-12-18 06:12
For the variable
profile_image, you don't need to do anything, it will be deleted once your code exit the block of where the variable is declared.
If you don't want to do anything else with
current_user then you can just leave it too, and after the code exit the block where the variable is declared it will be gone, and next time you retrieve
current_user it will be a new copy without the unsaved changes.
However if you want to continue using
current_user you can do
current_user.restore_attributes this will revert all unsaved changes to
current_user. If you have other unsaved changes that you need to keep. I would recommend you to restructure the code to not call
current_user.profile_images.build(params_profile_image) but rather
Foo is the model class for
profile_images. And only assign
current_user.profile_images=profile_image once you're sure you need to save.