Scaffold Ruby on Rails app with models and controllers
✓Works with OpenClaudeYou are a Ruby on Rails developer. The user wants to scaffold a Rails application with models and controllers using Rails generators.
What to check first
- Run
rails --versionto confirm Rails is installed (version 6.0+) - Verify Ruby is installed with
ruby -v(2.7.0 or higher recommended) - Check that you have a blank Rails app created or are ready to create one with
rails new myapp
Steps
- Create a new Rails application with
rails new myapp --skip-test(or omit--skip-testif you want test files) - Navigate into the app directory with
cd myapp - Generate a model with
rails generate model Post title:string content:text author:string(replace Post and attributes as needed) - Review the generated migration file in
db/migrate/to verify column types and constraints - Run
rails generate controller Poststo create a controller with associated views directory - Execute
rails db:migrateto apply the migration to your database - Add RESTful routes by uncommenting or adding
resources :postsinconfig/routes.rb - Generate a full scaffold with
rails generate scaffold Article name:string description:text published:booleanfor a complete CRUD setup with views
Code
# After running: rails new myapp && cd myapp
# 1. Generate a Post model with attributes
# rails generate model Post title:string content:text author:string published_at:datetime
# The migration file created in db/migrate/[timestamp]_create_posts.rb will look like:
# class CreatePosts < ActiveRecord::Migration[6.0]
# def change
# create_table :posts do |t|
# t.string :title
# t.text :content
# t.string :author
# t.datetime :published_at
# t.timestamps
# end
# end
# end
# 2. Generate a PostsController
# rails generate controller Posts index show new create edit update destroy
# 3. Add routes to config/routes.rb:
Rails.application.routes.draw do
resources :posts
end
# 4. Run migrations
# rails db:migrate
# 5. Add model validations in app/models/post.rb:
class Post < ApplicationRecord
validates :title, presence: true, length: { minimum: 5 }
validates :content, presence: true
validates :author, presence: true
end
# 6. Add basic controller actions in app/controllers/posts_controller.rb:
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
def index
@posts = Post.all
end
def show
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to @
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Ruby on Rails Skills
Other Claude Code skills in the same category — free to download.
Rails Active Record
Write Active Record models with associations and validations
Rails API
Build Rails API-only application with serializers
Rails Testing
Write RSpec tests with factories and mocks
Rails Stimulus
Build interactive UIs with Hotwire and Stimulus
Rails Sidekiq
Set up background jobs with Sidekiq
Rails ActiveRecord Performance Optimization
Fix N+1 queries, slow scopes, and ActiveRecord pitfalls in production Rails apps
Rails Action Cable WebSockets
Build real-time features in Rails using Action Cable WebSockets
Want a Ruby on Rails skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.