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:
- Create a database connection.
- Write the SQL query.
- Run this SQL query in the database.
- 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.