Rails 在 Model 中判断数据库是否存在?

lb563 · April 25, 2012 · Last by hhuai replied at April 25, 2012 · 3371 hits

情况是 class A < ActiveRecord::Base

end

class B < ActiveRecord::Base

end

model "A" 是链接系统 devironment 环境下的的数据库"student1"

model "B" 是链接系统 db1 环境下的的数据库"student2"

现在想找一种方法在 model "B" 判断 "db1"环境下的数据库是否存在,如果存在就链接,反之不链接!

class B < ActiveRecord::Base if db1[:database].exist? #这里是我自己猜想假如有这么一个方法 establish_connection :db1 end end

直接使用应该可以拦到 except

You need to Sign in before reply, if you don't have an account, please Sign up first.