Hola que tal.
Si, ya he leido como se conecta a multiples bases de datos. La pregunta
aqui es si existe algun metodo mas simplificado o algun cambio que se
haya hecho en Rails 2.
Para saber si lo hago de la manera “tradicional” (1.2) o la [aun mas]
facil (2) en caso de haberla.
Gracias.
PD: Manera tradicional :
class AbstractApplicationController < ActionController::Base
here, we hop into the front of the request-handling
pipeline to run a method called hijack_db
before_filter :hijack_db
here, we’re going to manually establish a connection
to the database we feel like connecting to.
def hijack_db
# completely ridiculous condition
is_odd = Time.now.hour % 2 == 1
# determine the database name
db_name = is_odd ? “dis_odd_db†: “dat_even_dbâ€
# lets manually connect to the proper db
ActiveRecord::Base.establish_connection(
:adapter => “mysqlâ€,
:host => “localhostâ€,
:username => “mr_robotoâ€,
:password => “secret_secret_i_got_a_secretâ€,
:database => db_name
)
end
end