a tabela de usuarios.rails generate scaffold user name:string email:string invoke active_record create db/migrate/20121127205353_create_users.rb create app/models/user.rb invoke test_unit create test/unit/user_test.rb create test/fixtures/users.yml invoke resource_route route resources :users invoke scaffold_controller create app/controllers/users_controller.rb invoke erb create app/views/users create app/views/users/index.html.erb create app/views/users/edit.html.erb create app/views/users/show.html.erb create app/views/users/new.html.erb create app/views/users/_form.html.erb invoke test_unit create test/functional/users_controller_test.rb invoke helper create app/helpers/users_helper.rb invoke test_unit create test/unit/helpers/users_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/users.js.coffee invoke scss create app/assets/stylesheets/users.css.scss invoke scss create app/assets/stylesheets/scaffolds.css.scssComo a tabela de usuarios deve ficar na base externa devemos tomar alguns procedimentos:1o - Alterar o arquivo app/models/user.rbclass User < ActiveRecord::Base attr_accessible :email, :nameendpara: class User < TestDB attr_accessible :email, :nameendsubstituir o ActiveRecord::Base por sua subclasse TestDB, assim, a aplicacao se onde encontrar a tabela users que sera criada.2o - Radar a migracao de forma apropriadarake db:migrate RAILS_ENV=database_externa_1 == CreateUsers: migrating ==================================================== -- create_table(:users) -> 0.0711s == CreateUsers: migrated (0.0712s) ===========================================passando a conexao "database_externa_1" como parametro, assim, a tabela sera criada no banco externo.Exemplo 2: Criar a tabela de projetos.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.scssComo a tabela de projetos deve ficar na base local:1o - Alterar o arquivo app/models/project.rbclass Project < ActiveRecord::Base attr_accessible :description, :name, :user_idendpara: class Project < ProjectDB attr_accessible :description, :name, :user_id belongs_to :userendsubstituir o ActiveRecord::Base por sua subclasse ProjectDB. Note que toda as relacoes entre os modelos podem ser construidas normalmente, para a aplicacao nao faz mais diferenca a sua localidade ou tipo. Entao configure o modelo "user" tambem:class User < TestDB attr_accessible :email, :name has_many :projectsend2o - Radar a migracao de forma apropriadarake db:migrate == CreateUsers: migrating ==================================================== -- create_table(:users) -> 0.0014s == CreateUsers: migrated (0.0015s) =========================================== == CreateProjects: migrating ================================================= -- create_table(:projects) -> 0.0014s == CreateProjects: migrated (0.0015s) ========================================Veja que nao a necessidade de passar a conexao com o parametro, pois sera utilizada a padrao do ambiente.Agora, todos os modelos do seu projeto devem herdar de ProjecDB e nao mais de ActiveRecord::Base.Pronto, isso e tudo o que voce deve saber para trabalhar com multiplas base de dados relacionais em seu projeto Ruby on Rails.Para testar, va ao 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:"