'Best way to return recently created object in ActiveRecord?

I'm creating an object that when called it will create an database record and I want this function to return the newly created object. This is what I got:

data = {foo: 'foo', bar: 'bar'}

Dummy.new(data).save! # true
Dummy.last # newest record in the database

I'm concerned about what this would mean when there are more than one sessions on the same database. Is there a sure-fire way of getting the record I just created?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source