You didn’t say what type of database you are using, but the place you should look is on ActiveRecord::ConnectionAdapters::AbstractAdapter – prefetch_primary_key?() and next_sequence_value(). You should probably look at subclassing this class, and returning false from prefetch_primary_key?. That will cause next_sequence_value to be called, and you can do what you need to there. The return from this function is assigned to the id of the ActiveRecord instance.
Take a look at the firebird or openbase adapters for examples.