ActiveRecord is thread safe
Published over 6 years ago

Yes it is. Believe it or not, ActiveRecord is thread fucken’ safe. Probably since Fri, 23 Jul 2004

But before you start your crazy thread shit, you should set :

ActiveRecord::Base.allow_concurrency = true

ActiveRecord::Base.allow_concurrency = true

And after you’re done:

ActiveRecord::Base.verify_active_connections!

ActiveRecord::Base.verify_active_connections!

The latter is useful to close stale open db connections, as each thread sets up it’s own connection when you have allow_concurrency set to true.

DISCLAIMER : The above post contains expletives that may not be suitable for children and the disclaimer is at the wrong end.