rails-generators
Skill1 starsChanged 19 days agoMITView on GitHub
Run the Rails, Bundler, and gem commands that write files instead of writing those files by hand. Use before creating a migration or changing the schema; before creating a model, controller, job, mailer, channel, Stimulus controller, component, rake task, or script; before changing credentials, gems, or importmap pins; when a migration fails or schema.rb has a merge conflict; or when asked which Rails command does something.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- captureSkill
- project-logSkill
- project-memorySkill
- rails-contextSkill
- rails-design-systemSkill
- rails-hotwireSkill
- rails-minitestSkill
- rails-view-componentSkill
- toolsmithSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Read Gemfile.lock for the Rails version, the database adapter, and the gems that bring generators (stimulus-rails, view_component, …
- Very specific: line 21
Read config.generators in config/application.rb, and list lib/templates/ and lib/generators/ if they exist.
- Very specific: line 22
Read config/database.yml for other databases (migrations_paths) and db/ for the schema format (schema.rb or structure.sql).
- Very specific: line 32
After a migration: read it, migrate, prove it reverses with bin/rails db:migrate:redo, and check that git diff db/schema.rb shows only your …
- Very specific: line 36
Credentials only through
bin/rails credentials:edit: Never write .yml.enc files or keys, never invent a secret, and check the command's …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rails generators and commands
When Rails, Bundler, or a gem has a command that writes a file, you run the command and then edit what it wrote. You never write that file from scratch, and never edit a file the framework owns. Commands get the details right that hand-written files get wrong: migration timestamps and version tags, the test and fixture beside a model, routes, Stimulus and Action Cable registration, vendored JavaScript, encrypted credentials, and the app's own generator settings.
The references/ files beside this file hold the detail. They ship with this skill, so resolve their paths from this skill's directory (${CLAUDE_SKILL_DIR}), not the app. Read the matching one first:
| Read | Before |
references/migrations.md | any schema change: generating, the name patterns and field syntax, running and reversing, editing a migration, schema.rb and its merge conflicts, data changes, production-safe patterns |
references/generators.md | any other generator: what each one writes, the app's generator settings, gem generators and installers, what has no generator |
references/commands.md | credentials, gems, JavaScript packages, app:update, routes, database tasks, runner and the other checks |
Detect first
- Read
Gemfile.lockfor the Rails version, the database adapter, and the gems that bring generators (stimulus-rails, view_component, importmap-rails or jsbundling-rails, strong_migrations, devise...). - Read
config.generatorsinconfig/application.rb, and listlib/templates/andlib/generators/if they exist. The generator follows them; know what it will produce. - Read
config/database.ymlfor other databases (migrations_paths) anddb/for the schema format (schema.rborstructure.sql). - Find how the app runs:
bin/railsdirectly, or inside Docker or a devcontainer (docker compose exec <service> bin/rails ...). Ifbin/railscannot boot, fix that first or tell the user - do not fall back to writing the files.
Rules
- Every schema change starts with
bin/rails generate migrationorbin/rails generate model. Never create a file indb/migrate/(ordb/<name>_migrate/) yourself, never pick or change a timestamp, never type theMigration[x.y]tag. Name it so the generator writes the body (AddSlugToPosts slug:string!:uniq,RemoveLegacyIdFromPosts legacy_id:integer,CreateJoinTableArtistsMusics artists musics); a name it cannot read gives an emptychangefor you to fill. Then edit the body it wrote - never silence the generator (> /dev/null) and overwrite the whole file. - Use the generator for every file kind it makes - model, controller, resource, scaffold, job, mailer, mailbox, channel, helper, task, script, system or integration test, Stimulus controller, component, a gem's installer. It writes the test, fixture, route, base class, and JavaScript registration that a hand-written file misses. Then edit the generated files to do the job.
- Look before you generate, and never let a generator overwrite. Run with
--pretendwhen unsure what it writes. Pass--skipwhenever a file might already exist: with no terminal to answer its overwrite prompt, a generator overwrites. Read the output - a name clash prints a message and exits 0 having written nothing. - Do not fight the app's generator settings. No
--primary-key-typein an app that sets it, no--no-fixturein an app that uses fixtures. Pass an option only to differ from the app on purpose, and say why. - Never edit a generated dump or lockfile:
db/schema.rb,db/structure.sql,db/<name>_schema.rb,Gemfile.lock, and package lockfiles. Change their source and run the command -db:migrate,bundle install, the package manager. A schema.rb merge conflict is resolved by migrating, not by merging lines (migrations.md). - After a migration: read it, migrate, prove it reverses with
bin/rails db:migrate:redo, and check thatgit diff db/schema.rbshows only your change. Commit the migration and the schema dump together. - Never edit a migration that is committed and shared, or deployed. Generate a new one. A migration that has run only locally is rolled back (
db:migrate:down VERSION=) before you edit it. - Keep data changes out of schema migrations where you can: a
bin/rails generate scriptscript run withbin/rails runner, or a separate migration that usesupdate_all, SQL, or a model class defined inside it - never the app's own model classes. - Write migrations safe for the app's database and deploys. On PostgreSQL or MySQL with live traffic, follow the safe patterns in
migrations.md(concurrent indexes, constraints validated later, columns ignored before removal) and anystrong_migrationsmessage. - Credentials only through
bin/rails credentials:edit. Never write.yml.encfiles or keys, never invent a secret, and check the command's output for "Invalid YAML" (commands.md). - Gems with
bundle add/bundle remove/bundle update NAME --conservative, importmap packages withbin/importmap pin, node packages with the app's package manager. A Gemfile edit followed bybundle installis fine; a hand-written pin or lockfile edit is not. - When a command fails, fix the cause (the app does not boot, a pending migration, a missing gem) and run it again. Writing the file by hand is not a fallback; if you cannot fix it, stop and tell the user what failed.
- Hand-write only what has no generator - concerns, service and form objects, policies without a gem generator, views for existing actions, and the bodies of generated files - after checking
bin/rails generatefor one.
The guard
This plugin ships a hook that refuses, before they happen, a new migration written with Write or a shell redirect, and any write to a schema dump, an encrypted credentials file, or Gemfile.lock, in any directory that has bin/rails. Its message names the command to run. Editing a migration that has already run - with Edit, or in the shell (sed -i, perl -pi, a glob such as db/migrate/*_create_users.rb) - gets a note, not a refusal. When the hook refuses, run the command it names; do not look for another way to write the file.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

