created in the outer database.Example 2: Create the design table.rails generate scaffold project user_id:integer name:string description:text invoke active_record create db/migrate/20121127212538_create_projects.rb create app/models/project.rb invoke test_unit create test/unit/project_test.rb create test/fixtures/projects.yml invoke resource_route route resources :projects invoke scaffold_controller create app/controllers/projects_controller.rb invoke erb create app/views/projects create app/views/projects/index.html.erb create app/views/projects/edit.html.erb create app/views/projects/show.html.erb create app/views/projects/new.html.erb create app/views/projects/_form.html.erb invoke test_unit create test/functional/projects_controller_test.rb invoke helper create app/helpers/projects_helper.rb invoke test_unit create test/unit/helpers/projects_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/projects.js.coffee invoke scss create app/assets/stylesheets/projects.css.scss invoke scss identical app/assets/stylesheets/scaffolds.css.scssAs the projects table must be in the local database:1o - Changing the file "app/models/project.rb"class Project < ActiveRecord::Base attr_accessible :description, :name, :user_idendto: class Project < ProjectDB attr_accessible :description, :name, :user_id belongs_to :userendreplace ActiveRecord::Base subclass by its ProjectDB. Note that all relations between the models can be built normally, for the application it not makes more difference the location or type of databases. Then configure the model "user" as well:class User < TestDB attr_accessible :email, :name has_many :projectsend2o - Run migration appropriatelyrake db:migrate == CreateUsers: migrating ==================================================== -- create_table(:users) -> 0.0014s == CreateUsers: migrated (0.0015s) =========================================== == CreateProjects: migrating ================================================= -- create_table(:projects) -> 0.0014s == CreateProjects: migrated (0.0015s) ========================================See it not need to pass the connection parameter, it will uses the default of each environment.Now, all models of your project must inherit from ProjecDB and not more of ActiveRecord::Base.Okay, that's all you need to know to work with multiple relational databases in your Ruby on Rails project.To test, go to terminal:rails cLoading development environment (Rails 3.2.8)1.9.3p194 :001 > User.create(:name => "AJ Alves", :email => "aj.alves@zerokol.com") (0.1ms) BEGIN SQL (0.3ms) INSERT INTO `users` (`created_at`, `email`, `name`, `updated_at`) VALUES ('2012-11-27 21:37:28', 'aj.alves@zerokol.com', 'AJ Alves', '2012-11-27 21:37:28') (36.6ms) COMMIT => #<user 21:37:28="21:37:28" 2="2" aj.alves="aj.alves" alves="alves" created_at:="created_at:" email:="email:" id:="id:" name:="name:" updated_at:="updated_at:" zerokol.com="zerokol.com"> 1.9.3p194 :002 > Project.create(:user_id => 1, :name => "Teste", :description => "Um projeto de teste") (0.0ms) begin transaction SQL (0.4ms) INSERT INTO "projects" ("created_at", "description", "name", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["created_at", Tue, 27 Nov 2012 21:38:16 UTC +00:00], ["description", "Um projeto de teste"], ["name", "Teste"], ["updated_at", Tue, 27 Nov 2012 21:38:16 UTC +00:00], ["user_id", 1]] (117.6ms) commit transaction => #<project 1="1" 21:38:16="21:38:16" 2="2" created_at:="created_at:" de="de" description:="description:" este="este" id:="id:" m="m" name:="name:" projeto="projeto" teste="teste" updated_at:="updated_at:" user_id:="user_id:"> 1.9.3p194 :003 > u = User.first User Load (0.4ms) SELECT `users`.* FROM `users` LIMIT 1 => #<user 1="1" 21:33:42="21:33:42" aj.zerokol="aj.zerokol" alves="alves" created_at:="created_at:" email:="email:" gmail.com="gmail.com" id:="id:" name:="name:" updated_at:="updated_at:"> 1.9.3p194 :004 > u.projects Project Load (0.2ms) SELECT "projects".* FROM "projects" WHERE "projects"."user_id" = 1 => [#<project 1="1" 21:33:58="21:33:58" created_at:="created_at:" d="d" description:="description:" dsfsdf="dsfsdf" este="este" id:="id:" name:="name:" sdf="sdf" sdfs="sdfs" updated_at:="updated_at:" user_id:="user_id:">, #<project 1="1" 21:38:16="21:38:16" 2="2" created_at:="created_at:" de="de" description:="description:" este="este" id:="id:" m="m" name:="name:" projeto="projeto" teste="teste" updated_at:="updated_at:" user_id:="user_id:">] 1.9.3p194 :005 > p = Project.first Project Load (0.2ms) SELECT "projects".* FROM "projects" LIMIT 1 => #<project 1="1" 21:33:58="21:33:58" created_at:="created_at:" d="d" description:="description:" dsfsdf="dsfsdf" este="este" id:="id:" name:="name:" sdf="sdf" sdfs="sdfs" updated_at:="updated_at:" user_id:="user_id:"> 1.9.3p194 :006 > p.user User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 => #<user 1="1" 21:33:42="21:33:42" aj.zerokol="aj.zerokol" alves="alves" created_at:="created_at:" email:="email:" gmail.com="gmail.com" id:="id:" name:="name:" updated_at:="updated_at:"> 1.9.3p194 :007 >