This skill helps you structure Rails controllers with thin actions, RESTful patterns, and safe parameter handling for maintainable apps.
npx playbooks add skill ag0os/rails-dev-plugin --skill rails-controller-patterns
Generate controllers following standard Rails RESTful conventions (7 actions, resourceful routing, before_actions, strong params).
rails-stack-profiles), native delegates to models and concerns, extracted delegates to service objectsparams.expect (Rails 8+)redirect_to after success, render :action, status: on failureCards::ClosuresController over post :close on CardsControllerparams.expect replaces params.require().permit() with a cleaner, more secure API. Check Gemfile.lock for Rails version before using.
# Basic
params.expect(post: [:title, :content])
# Arrays
params.expect(post: [:title, tags: []])
# Nested attributes
params.expect(user: [:name, :email, profile_attributes: [:bio, :avatar]])
# Dynamic hash attributes
params.expect(product: [:name, :price, metadata: {}])
# Legacy syntax (Rails < 8)
params.require(:post).permit(:title, :content)
Treat state changes as resources instead of adding custom member actions. This keeps controllers focused and RESTful.
# Bad - custom actions bloat the controller
resources :cards do
post :close
post :reopen
end
# Good - resource controllers
resources :cards do
scope module: :cards do
resource :closure # create = close, destroy = reopen
resource :pin # create = pin, destroy = unpin
end
end
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from ActionPolicy::Unauthorized, with: :forbidden
private
def not_found
respond_to do |format|
format.html { render "errors/not_found", status: :not_found }
format.json { render json: { error: "Not found" }, status: :not_found }
end
end
def forbidden
respond_to do |format|
format.html { redirect_back fallback_location: root_path, alert: "Not authorized." }
format.json { render json: { error: "Forbidden" }, status: :forbidden }
end
end
end
| Anti-Pattern | Problem | Fix |
|-------------|---------|-----|
| Fat controllers (50+ line actions) | Hard to test and maintain | Move logic to its axis-appropriate home (see Principle 1) |
| Business logic in controllers | Violates SRP | Move logic to its axis-appropriate home (see Principle 1) |
| Custom member actions (:close, :archive) | Controller grows unbounded | Create dedicated resource controllers (Cards::ClosuresController) |
| params.permit! | Allows all params (mass assignment) | Use params.expect with explicit fields |
| Deeply nested routes (>1 level) | Confusing URLs and helpers | Use shallow: true or flat routes |
| Skipping authentication filters | Security vulnerability | Apply before_action broadly, skip selectively |
| Multiple respond_to blocks | Code duplication | Use respond_to once or separate API controllers |
status: :unprocessable_entity (422) for validation failuresstatus: :not_found (404) for missing recordsstatus: :forbidden (403) for authorization failuresstatus: :see_other (303) for redirect_to after DELETErescue_from in ApplicationController for consistent error responsesWhen analyzing or creating controllers, provide:
config/routes.rbWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.