简体   繁体   中英

Ruby On Rails 5.2 and Multiple Databases

I have three different database systems my Rails application needs to access at the same time.

We have SQL Server, an Oracle server, and of course Postgres.

I have tried to figure out how to achieve the ability to grab data from all three (multiverse, etc..).

All I get is a vague error:

ActiveRecord::Base.establish_connection ActiveRecord::AdapterNotSpecified in UsersController#index database configuration does not specify adapter

I have database.yml and database_nba.yml which holds access to the second SQL server and cannot get it to work with two concurrent database servers.

You have to specify the different databases in your database.yml

production:
  adapter:mysql, :other_adapter, :other_adapter

https://www.rubydoc.info/docs/rails/4.1.7/ActiveRecord/ConnectionAdapters

Check the above docs.

In order to access different databases at the same time you have to create models specific to those databases. Once you do that, depending on the object you create it talks to the appropriate backend database.

https://www.google.com/amp/s/www.thegreatcodeadventure.com/managing-multiple-databases-in-a-single-rails-application/amp/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM