rails-controllers

Implement RESTful Rails controllers with thin actions and delegated model behavior.

2|Updated May 15, 2015
One-click install
npx skills add https://github.com/stephendolan/dotfiles --skill rails-controllers
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-controllers
Source: https://github.com/stephendolan/dotfiles/tree/main/claude/skills/rails-controllers
Command: npx skills add https://github.com/stephendolan/dotfiles --skill rails-controllers

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill promotes RESTful controller design, thin controllers, and domain-model-driven behavior.

Core Features & Use Cases

  • Resources Over Verbs: Prefer resources and nested controllers over custom actions.
  • Thin Controllers: Delegate complex behavior to models/services.
  • Error Handling & Authorization: Centralized patterns for authorization and error responses.

Quick Start

Add a thin controller action that delegates to a model method and redirects appropriately.

Frequently Asked Questions about rails-controllers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure RESTful controllers in Rails to follow REST conventions?

RESTful Rails controllers map CRUD actions to standard HTTP methods (GET, POST, PUT, DELETE) on resources. Use Rails resourceful routing to automatically generate seven standard actions—index, show, new, create, edit, update, destroy—that correspond to REST principles, keeping each action focused on a single responsibility.

What's the best way to keep Rails controllers thin and move logic to models?

Thin controllers delegate complex behavior to domain models and service objects. Move business logic, validations, and data transformations out of controller actions into model methods, so controllers only handle HTTP concerns: routing, parameter extraction, authorization checks, and response formatting.

How do I implement authorization and error handling consistently across Rails controllers?

Centralize authorization and error responses using before_action filters and rescue_from blocks. Define authorization logic in a shared concern or base controller, and standardize error responses—returning appropriate HTTP status codes and JSON payloads—so all endpoints behave consistently.

Should I use custom controller actions or nested resources in Rails?

Prefer nested resources and standard REST actions over custom actions. Nested controllers—like /posts/:post_id/comments—map domain relationships to URL structure naturally. Custom actions (like /posts/:id/publish) obscure intent; use POST to a resource or a state-transition pattern instead.

How do I handle parameter validation and idempotency in Rails REST endpoints?

Validate parameters in model layers using Rails validations or form objects, then check results in the controller. For idempotent endpoints (PUT, PATCH), design updates to succeed safely when repeated; use conditional requests (ETags) and ensure side effects occur only on state change.

Can I use Rails controllers for APIs and web views with the same patterns?

Yes. RESTful controller patterns work for both JSON APIs and HTML rendering. Use respond_to or content negotiation to serve different formats from the same action, keeping controller logic identical—only the view or serializer layer changes based on requested media type.