在Rails中释放连接

时间:2011-04-30 00:32:40

标签: ruby-on-rails ruby

我正在使用Rails 2.3.8。

将模型上的连接发布到另一个数据库的最佳方法是什么?

假设我有ModelB.establish_connection(“server_b”)

ModelB.remove_connection可以解决这个问题吗?我如何验证我是否已成功删除连接?

1 个答案:

答案 0 :(得分:0)

看起来remove_connection就像你正在寻找的那样。要验证您是否已成功删除连接,可以将find方法包装在救援块中,如:

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