DEV Community


Posted on

What is Active Record

To non-programmers this might sound like a recording label. However, in computer programming what is Active record? active record is a ruby gem that handles the database stuff without worrying to much about writing SQL.

Object/Relational Mapping (ORM)
ORM stands for Object-Relational-Mapping. Essentially, Active Record takes data stored in a relational database, which needs to be modified or retrieved by writing SQL statements. Developers can interact with that data using Ruby object.

Example without Active Record

class User
  attr_accessor :name

  @@all = []

  def initialize(name)
      @name = name
      @@all << self

  def self.all
Enter fullscreen mode Exit fullscreen mode

Example with Active Record

class User < ActiveRecord::Base

Enter fullscreen mode Exit fullscreen mode

Top comments (0)