Establish a 2nd database connection in Rails

OK, you can find some howto’s everywhere on the web but only on this site I found the complete solution:

[sourcecode language=’ruby’]
class SecondConnection < ActiveRecord::Base SecondConnection.establish_connection( :adapter => “informix”,
:host => “localhost”,
:username => “hansnase”,
:password => “very_secret”,
:database => “ccdb@localhost”

self.abstract_class = true

“self.abstract_class = true” makes the thing actually work. Otherwise Rails seems to cache the database connection and does not switch back if you access any other classes but SecondConnection.


Later: Not so Yeah…

I had to establish another call to
[sourcecode language=’ruby’]
ActiveRecord::Base.establish_connection { “Establishing Base Connection” }

I assume it’s either an Informix problem or related to the old rails version I’m driving with.
Nevertheless: It works now.