What is Rails ActiveRecord?

Jam
3 min readAug 17, 2020

Active Record is the M in MVC — the model — which is the layer of the system responsible for representing business data and logic.
[Source: https://guides.rubyonrails.org/active_record_basics.html]

Rails Active Records provide an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records. Ruby method names are automatically generated from the field names of database tables.

Each ActiveRecord object has a CRUD (Create, Read, Update, and Delete) methods for database access.

This strategy allows for simple designs and straight forward mappings between database tables and application objects.

[Source: https://www.tutorialspoint.com/ruby-on-rails/rails-active-records.htm]

When we want to run a SQL query in database server, we normally do it in few steps:

  1. Create a database connection.
  2. Write the SQL query.
  3. Run this SQL query in the database.
  4. And get data from the database.

So, we need to do many tasks to run a simple database query.

But, ActiveRecord did most of these tasks for us. In ActiveRecord, we do not even need to write SQL queries.

--

--

Jam

Software engineer | Full Stack Developer | Programmer | Designer & Entrepreneur