> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# Connecting Ruby & Active Record Without Rails
- URL: https://til.codes/connecting-a-ruby-app-to-active-record-without-rails/
- Published: 2016-01-01T17:06:41.000Z
- Updated: 2016-01-01T17:06:41.000Z
- Author: Manu Ajith
- Tags: ruby, rails, postgres, postgresql, active-record, #Import 2024-07-13 21:01

```
require 'active_record'
require 'mysql2' # or 'pg' or 'sqlite3'

# Change the following to reflect your database settings
ActiveRecord::Base.establish_connection(
  adapter:  'mysql2', # or 'postgresql' or 'sqlite3'
  host:     'localhost',
  database: 'your_database',
  username: 'your_username',
  password: 'your_password'
)

# Define your classes based on the database, as always
class YourModel < ActiveRecord::Base
end

```