Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="http://apidock.com/rails/ActiveRecord/ConnectionHandling/establish_connection" rel="nofollow">ActiveRecord::ConnectionHandling.establish_connection</a> function call to connect to your database. You should be able to establish a connection with a different user even on every page if you would like, or look up the database credentials in a User model.</p> <p>If you are doing this, you might consider subclassing <code>ActiveRecord::Base</code> and overriding the <code>connection</code> call, which would then be used by every model to connect to the database.</p> <p>If you want to completely avoid a connection to the database before you explicitly set up the credentials through your application, then you probably want to initialize Rails without loading all of the ActiveRecord specific stuff. In that case, you will need to remove ActiveRecord from the initialization of Rails by putting this line in your <code>config/environment.rb</code>, within the <code>Rails::Initializer.run do |config|</code> block:</p> <pre><code>config.frameworks -= [ :active_record ] </code></pre> <p>Then you will need to load all of the ActiveRecord specific things once you have the credentials.</p> <p>Alternatively, you can override <code>Rails::Initialize::initialize_database</code> which is where the actual database connection is being used by putting this in your environment.rb before the <code>Rails::Initializer.run</code> call:</p> <pre><code>module Rails class Initializer def initialize_database nil end end end </code></pre> <p>Prior to rails 4.x you would use <a href="http://apidock.com/rails/ActiveRecord/Base/establish_connection/class" rel="nofollow">ActiveRecord::Base.establish_connection</a>, which is now deprecated.</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