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

后端 未结 4 538
耶瑟儿~
耶瑟儿~ 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:06

    It's been a while since this question has been created, but I have to say that there is another way too:

    conn_config = ActiveRecord::Base.connection_config
    conn_config[:database] = new_database
    ActiveRecord::Base.establish_connection conn_config
    

提交回复
热议问题