🧙 Part 4 — ActiveRecord Magic: Rails’ Powerful ORM
hmza

hmza @hmzas

About: `Git commit -m 'Hope it works'.` `404: Social life not found.`

Location:
Mars
Joined:
Aug 6, 2024

🧙 Part 4 — ActiveRecord Magic: Rails’ Powerful ORM

Publish Date: Jul 15
5 0

🧙 Part 4 — ActiveRecord Magic: Rails’ Powerful ORM

ActiveRecord lets you interact with the database using plain Ruby.

Example migration:


create_table :posts do |t|  
  t.string :title  
  t.text :content  
  t.timestamps  
end  

Enter fullscreen mode Exit fullscreen mode

And in your model:


class Post < ApplicationRecord  
  validates :title, presence: true  
end  

Enter fullscreen mode Exit fullscreen mode

Now, interact easily:


Post.create(title: "Hello Rails!", content: "First post.")  
Post.all  
Post.find(1)  

Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment