0Pricing
Ruby Academy · Lesson

Active Record Basics

ORM fundamentals.

What Is Active Record?

Active Record is the ORM (Object-Relational Mapper) layer of Rails. It connects Ruby objects to rows in a database table so you work with objects instead of raw SQL.

  • A class maps to a table.
  • An instance maps to a row.
  • An attribute maps to a column.

Defining a Model

A model is a class that inherits from ApplicationRecord (which inherits from ActiveRecord::Base). By convention a User model maps to the users table automatically.

class User < ApplicationRecord
end

# Maps to the 'users' table
# Columns become attributes automatically

All lessons in this course

  1. Active Record Basics
  2. Migrations
  3. Associations
  4. Validations and Queries
← Back to Ruby Academy