How can I dynamically change the Active Record database for all models in Ruby on Rails?

后端 未结 4 542
耶瑟儿~
耶瑟儿~ 2020-12-12 16:42

In our program, each customer gets their own database. We e-mail them a link that connects them to their database. The link contains a GUID that lets the program know whic

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 17:24

    you can change the connection to ActiveRecord at any time by calling ActiveRecord::Base.establish_connection(...)

    IE:

     ActiveRecord::Base.establish_connection({:adapter => "mysql", :database => new_name, :host => "olddev",
        :username => "root", :password => "password" })
    

提交回复
热议问题