title: How to connect to an existing database in Ruby on Rails
body: <p>I have a table named <strong>User</strong> at my project and I want to access another database of an another existing project. The database that I want to access it makes part of a project that I need to conceed access to my table User. The reason is that my table User that is responsable to authenticate an user base, and after their authentication they will return a <strong>token</strong> and so they can access the another database. <strong>The database.yml</strong> <strong>of my table User</strong> is configured like this :</p>
  
  <pre><code>default: &amp;default
    adapter: sqlite3
    pool: &lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&gt;
    timeout: 5000
  
  development:
    &lt;&lt;: *default
    database: db/development.sqlite3
  
  test:
    &lt;&lt;: *default
    database: db/test.sqlite3
  
  production:
    &lt;&lt;: *default
    database: db/production.sqlite3
  </code></pre>
  
  <p>The database of the another project that I want to access is configured as follows :</p>
  
  <pre><code>default: &amp;default
    adapter: mysql2
    encoding: utf8mb4
    collation: utf8mb4_bin
    pool: &lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&gt;
    timeout: 5000
    variables:
      sql_mode: TRADITIONAL
  
  development:
    &lt;&lt;: *default
    username: root
    password:
    database: &lt;company_name&gt;dev
  
  test:
    &lt;&lt;: *default
    database: &lt;company_name&gt;_test
    username: root
    password:
  
  production:
    &lt;&lt;: *default
    database: &lt;%= ENV['RDS_DB_NAME'] %&gt;
    username: &lt;%= ENV['RDS_USERNAME'] %&gt;
    password: &lt;%= ENV['RDS_PASSWORD'] %&gt;
    host: &lt;%= ENV['RDS_HOSTNAME'] %&gt;
    port: &lt;%= ENV['RDS_PORT'] %&gt;
  </code></pre>
  
  <p>How can I solve this problem ?</p>