Active Record for Ruby on Railss
Active Record is the Rails object-relational mapper that connects Ruby classes to database tables. Models define validations and associations, migrations change the schema over time, and query methods like where, order and includes build SQL for you. It is the data layer of a Rails application.
Stage: Rails Core · Part of the Ruby on Rails roadmap · Last reviewed 19 November 2026
What to learn in Active Record
- Create a migration that adds a table and an index
- Declare has_many and belongs_to associations
- Add validations and show their errors
- Write queries with where, order and limit
- Avoid N+1 queries using includes
Active Record interview questions
What is an N+1 query and how do you fix it in Rails?
It happens when loading a list runs one query, then one extra query per record to fetch an association. Use includes (or preload or eager_load) so Rails loads the related records in a few queries. Tools like Bullet can detect these.
Why should schema changes use migrations?
Migrations are versioned Ruby files that apply and reverse changes to the database. They let every environment reach the same schema in order, and they are committed to version control, so teammates and servers stay in sync.
Where Active Record fits in the Ruby on Rails roadmap
Active Record belongs to the Rails Core stage (beginner level), which takes about 25 hours. MVC.
Other units in this stage
Back to the full Ruby on Rails roadmap