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.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
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.