Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You want <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-establish_connection" rel="noreferrer">ActiveRecord::Base#establish_connection</a>. You'll probably want to use it in an abstract subclass so that models using the manual connections don't disturb the connection uses by the rest of your application:</p> <pre><code>class LogBase &lt; ActiveRecord::Base self.abstract_class = true end class LogItem &lt; LogBase ... end LogItem.establish_connection { ... } LogItem.find_by_ ... </code></pre> <p>If you'll only ever have one model that makes manual connections the abstract class is unnecessary. </p> <p>Do you know the full set of databases that you might connect to? If so, database.yml may still be useful to you. You can put all the information in there as a directory, giving each database a name, then dynamically chose which one to establish_connection with in the application using those names:</p> <pre><code># database.yml atlanta: host: atlantadb.foo.com # foo.rb LogItem.establish_connection :atlanta </code></pre> <p>Setting up connections can be pretty heavyweight, doubly so if the sites are separated by wide area network. I'd consider whether it makes more sense to use an extract-transform-load approach and use a hourly/daily cron job to copy the data to a centralized reporting site. This is the most basic form of a data warehouse, and is a very commonly used approach. If you're using MySql, <a href="http://www.maatkit.org/tools.html" rel="noreferrer">Maatkit Sync</a> is a neat little tool, like rsync for tables. Alternately you probably use a database that supports master-slave replication, though that can be considerably more complicated to maintain.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload