While working with a multiple-database application I came across the point where I had to juggle between different environment configurations.
I had to pass connection hash to ActiveRecord::Base.establish_connection, something like this:
ActiveRecord::Base.establish_connection ( :adapter=>"mysql", :host=>"localhost", :username=>"myuser", :password=>"mypass", :database => "somedatabase" )
This connection can be easily retrieved from ActiveRecord::Base.configurations, this is currently undocumented.
Using ActiveRecord::Base.configurations, the above can be simply written as: