$ recombobulate _
home / tips / generate-ruby-on-rails-models-and-migrations-with-claude
0

Generate Ruby on Rails Models and Migrations with Claude

bagwaa @bagwaa · Mar 26, 2026 · Workflows
generate-ruby-on-rails-models-and-migrations-with-claude

Writing Rails migrations and models by hand means remembering column types, index syntax, and association macros every time. Claude can generate the whole stack from a plain-English description.

Create a Rails data model for a project management app with:
- Users (name, email, timestamps)
- Projects (belongs to user, name, description, status enum)
- Tasks (belongs to project, title, due_date, completed boolean)
- Add appropriate indexes and foreign keys

Claude will output migration files with the correct create_table syntax and a matching set of ActiveRecord models complete with belongs_to, has_many, validations, and scope suggestions. For enums, it will use Rails' built-in enum macro and suggest a sensible set of values.

It also knows to add null: false constraints and database-level indexes for foreign keys — the kind of detail that's easy to forget in a first pass.

# Claude-generated snippet
class Task < ApplicationRecord
  belongs_to :project
  scope :incomplete, -> { where(completed: false) }
  scope :overdue, -> { where("due_date < ?", Date.today).incomplete }
  validates :title, presence: true
end

You can follow up with "add a polymorphic comments association" or "generate factory_bot factories for all three models" to keep the momentum going.

Tell Claude what your domain looks like, and it'll give you Rails-ready code that follows conventions from migrations all the way to model validations.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago