The code here is a tech demo showing how to switch between databases in Rails 5, in a thread-safe manner.
The simple way to switch databases is:
ActiveRecord::Base.establish_connection :user_shard1
puts User.find(1) # this is executed on the database keyed on "user_shard1" in database.yml
ActiveRecord::Base.establish_connection :development