These 13 Ruby on Rails prompts help ChatGPT, Claude, Claude Code and Codex write Rails code that matches your version: Active Record without N+1 queries, strong parameters with params.expect, Solid Queue jobs that survive restarts, Minitest and system tests, and step-by-step upgrades to Rails 8.1. Each prompt is a template with blanks you fill in.
How to use these prompts
Copy a prompt, replace each blank in double braces, or keep the default after the colon. {{rails_version:8.1}} means Rails 8.1 unless you change it.
State your versions. As of 26 October 2026, the Rails Guides are for Rails 8.1.4, and the Rails maintenance policy lists security fixes for 8.1 until 10 October 2027 and for 8.0 until 7 November 2026. Rails 8.1 added Active Job Continuations, structured event reporting, local CI with bin/ci and deprecated associations, so a model that doesn't know your version may not use them.
Paste the model with the code that uses it. A controller alone hides the associations and callbacks that cause extra queries. Mention your front end too: Hotwire, a JSON API, or a separate client.
In an agent, let it run bin/rails test after each change, and bin/rails test:system for browser tests, which bin/rails test skips by default.
Which Rails defaults should you mention in a prompt?
Recent Rails versions added defaults that a model may not assume on its own. Naming your choice saves a round of corrections.
| Topic | Common alternative | Rails default for new apps |
|---|---|---|
| Background jobs | Sidekiq with Redis | Solid Queue, database-backed, since Rails 8.0 |
| Strong parameters | params.require(...).permit(...) |
params.expect(...) |
| Authentication | A third-party gem | bin/rails generate authentication since Rails 8.0 |
| Tests | RSpec | Minitest with fixtures |
| CI steps | Only in the hosted CI file | config/ci.rb run with bin/ci in Rails 8.1 |
If your app uses Sidekiq, RSpec or Devise, say so, and the model should follow your stack instead.
How do you write Active Record code that stays fast?
1. Find and fix N+1 queries
The Active Record Querying guide recommends includes, which picks preload or eager_load for you, and strict_loading to raise an error when a record lazily loads an association.
This page runs {{count:140}} queries. Here are the models, the
controller action and the view:
{{code}}
Find every N+1 pattern. Fix each with includes, preload or eager_load,
and say which you chose and why (conditions on the association need
eager_load or joins). Use counter caches or a grouped count where we
only show totals. Then suggest where to turn on strict_loading in
development and which code paths will start raising. Add a test that
fails if the query count grows.
2. Design models and migrations from a spec
Design the Rails {{rails_version:8.1}} models and migrations for:
{{spec}}
For each table: columns with types and null constraints, foreign keys
with an on_delete choice explained, unique and composite indexes for
the queries in the spec, and database-level defaults. For each model:
associations with dependent options, validations that match the
database constraints, enums with explicit values, and scopes for the
common queries. List the queries you expect and which index serves
each.
3. Mark an old association as deprecated
Rails 8.1 lets you write has_many :posts, deprecated: true to report every use of an association, with :warn, :raise or :notify modes, per the Rails 8.1 release notes.
We want to remove the {{association:legacy_orders}} association from
this model:
{{model}}
Mark it deprecated: true in Rails 8.1, and tell me which reporting mode
to use in development, test and production. Search the code I paste
below for every use, including through, preload and nested attributes,
and give a removal plan in small pull requests.
{{usages}}
How do you write safe controllers?
4. Convert strong parameters to params.expect
The Action Controller guide says "The expect method provides a concise and safe way to require and permit parameters," and returns a 400 Bad Request when the structure doesn't match.
Update the strong parameters in these controllers to params.expect:
{{controllers}}
Keep the permitted keys exactly the same, including nested attributes
and arrays. Point out any key that is permitted but never used, and
any attribute an attacker could set that they shouldn't, such as role
or account_id. Add a controller or integration test showing a
malformed request now gets a 400 instead of a 500.
5. Add authentication with the Rails generator
The Rails security guide says "Starting with version 8.0, Rails comes with a default authentication generator," run with bin/rails generate authentication, and shows rate_limit to: 10, within: 3.minutes, only: :create in the sessions controller.
Add authentication to this Rails {{rails_version:8.1}} app using
bin/rails generate authentication. Our User model today:
{{model}}
Explain what the generator creates and how it fits our existing users
table. Add a password length validation, since has_secure_password
doesn't check length or complexity. Keep the rate limit on sessions,
add sign-up if the generator doesn't, and list the routes that should
require a signed-in user. Add tests for sign in, sign out and a
locked-out attempt.
6. Slim down a fat controller
This controller action does too much:
{{code}}
Refactor it: keep parameter handling and the response in the
controller, move the business logic into a plain Ruby object with one
public method, and wrap multi-step writes in a transaction. Remove
callbacks that hide side effects if they belong in the new object.
Keep routes and responses the same. Show each file and a test for the
new object plus an integration test for the action.
How do you build background jobs that don't break?
7. Move slow work into a job
The Active Job guide says Solid Queue is "the default queue backend for Rails version 8.0 onwards" and that "A failed job will not be retried, unless configured otherwise."
This request {{work:builds a CSV export and emails it}} and takes
several seconds:
{{code}}
Move the work into an Active Job using Solid Queue. Pass record IDs,
not large objects. Set enqueue_after_transaction_commit so the job
never runs before the data is saved. Add retry_on for errors worth
retrying with a wait, discard_on for ones that aren't, and make the
job idempotent so a retry can't send two emails. Add a test with
assert_enqueued_with and one that performs the job.
8. Make a long job resumable with continuations
Rails 8.1 adds ActiveJob::Continuable: a job split into steps resumes from the last completed step after a restart, and a step can save a cursor to pick up mid-loop.
This job processes {{items:all invoices for a month}} and gets killed
during deploys, then starts over:
{{job}}
Rewrite it with ActiveJob::Continuable in Rails 8.1. Split it into
steps, use a cursor and step.advance! in the loop so progress is saved,
and make each step safe to run twice. Explain what happens if the job
is interrupted in the middle of each step. Add a test that interrupts
and resumes it.
How do you test a Rails app?
9. Write model and integration tests
The Rails testing guide calls Minitest "the default testing library used by Rails" and describes fixtures as YAML files in test/fixtures.
Write {{framework:Minitest}} tests for this Rails feature:
{{code}}
Cover model validations and scopes, then an integration test for the
request flow: the happy path, invalid params, a signed-out user and a
user without access. Use fixtures (or factories if I said RSpec),
assert database changes with assert_difference, and check the
response status and redirect. Name each test after the behavior it
checks.
10. Write a system test for a Hotwire page
Write a Rails system test for this page that uses Turbo and Stimulus:
{{view_and_controller}}
Use Capybara with the driver set in application_system_test_case.rb.
Test what a user sees: fill in the form, submit, and assert the Turbo
Stream update appears without a full page load. Wait for content with
Capybara matchers instead of sleep. Cover one validation error shown
inline. Tell me how to run it with bin/rails test:system.
11. Set up local CI with bin/ci
Rails 8.1 adds a CI DSL in config/ci.rb that you run with bin/ci, with steps such as step "Tests: Rails", "bin/rails test".
Write a config/ci.rb for our Rails 8.1 app that runs the same checks as
our hosted CI. Our current CI file:
{{ci_file}}
Include steps for setup, style checks, security scanning, unit and
integration tests, and system tests, in an order that fails fast. Keep
step names short and clear. Then simplify the hosted CI file so it
calls bin/ci instead of repeating each command.
How do you upgrade Rails?
12. Plan an upgrade to the next Rails version
The Rails upgrading guide advises moving "one minor version at a time," running bin/rails app:update after changing the Gemfile, and turning on the settings in new_framework_defaults_X_Y.rb gradually before flipping config.load_defaults.
Plan an upgrade from Rails {{from:7.2}} to {{to:8.1}}. Here is our
Gemfile, Gemfile.lock and config/application.rb:
{{files}}
Lay out each minor version step. For each: the Ruby version needed,
gems that need new versions, what bin/rails app:update will change, and
which new framework defaults to enable one at a time, riskiest last.
Tell me which tests to run after each step, and mark anything you're
unsure applies to us.
13. Write custom AI guidelines for your app
Read these parts of our Rails app:
{{files}}
Write a short guidelines file for AI coding agents working on it, such
as AGENTS.md or CLAUDE.md. Cover only conventions specific to us: where
business logic lives, how we name service objects and jobs, which gems
to use for what, how we handle money and time zones, and test rules.
Use short imperative bullets and stay under 60 lines. List conventions
that look inconsistent in the code so we can pick one.
Turn your favorite one into a skill
If you run the N+1 or job prompt on every feature, make it a skill so Claude Code or Codex applies it when the task matches. Paste the prompt into the free SKILL.md generator to get a valid SKILL.md in your browser. The AGENTS.md guide explains where project guidelines from prompt 13 go, and the SQL prompts help when a query needs work below Active Record.
To keep these prompts one shortcut away, save them in Kipt. Your prompts live as Markdown in a private GitHub repo you own, blanks like {{rails_version:8.1}} stay fillable, and Cmd+K finds any prompt by name or tag.