Skills

Crud Patterns

Generates RESTful controllers mapping any action to CRUD by creating new resources...

Install

npx skills add ThibautBaissac/rails_ai_agents --skill crud-patterns -g -a claude-code -y
Category
Design
Updated
5mo ago
License
MIT
Context cost
Mediumabout 1,510 tokens
Runs scripts
No, instructions only

What it does

Generates RESTful controllers mapping any action to CRUD by creating new resources instead of custom actions. Use when adding features, creating controllers, designing routes, or handling state changes via REST. WHEN NOT: Non-REST APIs (use api-patterns), view/template work (use turbo-patterns), or model business logic (use model-patterns).

CRUD Patterns (37signals)

Map any action to CRUD. When something doesn't fit standard CRUD, create a new resource.

Project knowledge

Tech Stack: Rails 8.2 (edge), Turbo, Stimulus, Solid Queue, MySQL/SQLite Routing: Use scope module: for namespacing nested resources Controllers: Thin with concerns for shared behavior

Commands:

bin/rails routes | grep cards              # Check routes
bin/rails generate controller cards/closures  # Generate controller
bin/rails test test/controllers/           # Run controller tests

Resource thinking

When asked to add functionality, ask: "What resource does this represent?"

User requestResource to create
"Let users close cards"Cards::ClosuresController (create/destroy)
"Let users mark important"Cards::GoldnessesController (create/destroy)
"Let users follow a card"Cards::WatchesController (create/destroy)
"Let users assign cards"Cards::AssignmentsController (create/destroy)
"Let users publish boards"Boards::PublicationsController (create/destroy)
"Let users position cards"Cards::PositionsController (update)
"Let users archive projects"Projects::ArchivalsController (create/destroy)

State change controllers (singular resources)

Toggle state via POST (create) and DELETE (destroy) on a singular resource:

# app/controllers/cards/closures_controller.rb
class Cards::ClosuresController < ApplicationController
  include CardScoped  # Provides @card, @board

  def create
    @card.close
    render_card_replacement
  end

  def destroy
    @card.reopen
    render_card_replacement
  end
end

Standard CRUD controllers (plural resources)

# app/controllers/cards/comments_controller.rb
class Cards::CommentsController < ApplicationController
  include CardScoped

  def index
    @comments = @card.comments.recent
  end

  def create
    @comment = @card.comments.create!(comment_params)
Read the whole SKILL.md on GitHub

More in Design