You should probably read some information about the ActiveRecord object callback chain ; he explains what happens under the hood with your objects.
Basically, when you call save, the ActiveRecord :: Base object will go through all the callbacks in the order specified in the documentation, you can see where the commit happens (in between steps 6 and 7 at the time of writing this). ActiveRecord even provides a callback after committing in case you want to get some conditional logic when you are sure that something has been transferred to the database, but, as a rule, we trust that if save returns true, everything is fine .
In order to explicitly answer your question, the commit occurs during the save call, and not when the method exits.
source share