2011-04-30 60 views
2

我正在使用Rails 2.3.8。在Rails中释放连接

将模型上的连接释放到另一个数据库的最佳方式是什么?

比方说,我有ModelB.establish_connection( “SERVER_B”)

会ModelB.remove_connection做的伎俩?我如何确认我已成功删除连接?

回答

0

看起来好像remove_connection是你在找什么。要确认您已成功删除连接,可以在搜索框中包装查找方法,如下所示:

begin 
    ModelB.find(1) 
rescue ConnectionNotEstablished 
    # if we're here, then we have no connection, which is good in this case 
else 
    # if we're here, then we still have a connection, which is bad... 
end