
The Hidden DSL Inside Every Rails Model
June 10, 2026
Most Rails developers use belongs_to, has_many, scope, and validates every day.
We type them almost without thinking.
class User < ApplicationRecord
belongs_to :company
validates :email, presence: true
scope :active, -> { where(active: true) }
end
But here’s something interesting:
None of those are Ruby keywords.
They’re methods.
In fact, a Rails model is less like a traditional Ruby class and more like a Domain Specific Language (DSL) built on top of Ruby.
Once you see it, it’s hard to unsee.
<!-- CONTENT + GRADIENT OVERLAY -->
Built for Ruby on Rails
Build Maps Without
Google APIs
Generate beautiful production-ready maps directly from your Rails backend. Fast rendering, zero external dependencies, full control.
✓ No API fees✓ Self-hosted✓ Rails Native✓ Fast Rendering
Why developers switch
Replace expensive map stacks.
Stop relying on third-party map billing and bloated JS libraries. Render static or dynamic maps directly in Ruby.
The Empty Model
A Rails model starts life as a completely ordinary Ruby class.
class User < ApplicationRecord
end
At first glance, there’s nothing special here.
User inherits from ApplicationRecord, which inherits from ActiveRecord::Base.
That’s where the magic begins.
By inheriting from Active Record, the class gains hundreds of methods that allow us to describe data, relationships, validations, callbacks, and behavior using a concise DSL.
Associations
Consider this:
class User < ApplicationRecord
belongs_to :company
has_many :posts
end
When Rails reads these lines, it isn’t creating relationships in the database.
It’s executing methods.
Those methods generate additional behavior behind the scenes.
After declaring belongs_to :company, Rails creates methods such as:


Top comments (0)