rails-controller

Generate Rails API controllers with service delegation and standardized JSON responses.

Updated Oct 12, 2024
One-click install
npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-controller-samrocks03
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-controller
Source: https://github.com/samrocks03/shuttle-office-service/tree/main/.claude/skills/rails-controller
Command: npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-controller-samrocks03

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails API controllers in large Rails apps often become bloated and inconsistent. This Skill ensures controllers stay thin, authenticate requests, delegate business logic to services, and return standardized JSON responses with correct HTTP status codes.

Core Features & Use Cases

  • Thin controllers that delegate to service objects under Api::V1.
  • Standardized responses with consistent success/failure formats and appropriate HTTP statuses.
  • Authentication & Authorization with before_action hooks, ensuring secure access.
  • Guidance for new endpoints and consistent patterns for create/show/update/destroy actions.

Quick Start

Create or modify a controller to follow the project's API controller patterns and use a service object for business logic.

Frequently Asked Questions about rails-controller

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

FAQPage Schema
How do I keep my Rails API controllers thin and consistent?

To keep Rails API controllers thin, delegate business logic to service objects and standardize JSON responses. This ensures controllers handle authentication and HTTP status codes without becoming bloated.

What's the best way to structure JSON responses and HTTP status codes in a Rails API?

Standardizing JSON responses in a Rails API involves using consistent success and failure formats alongside correct HTTP status codes. This ensures predictable API behavior across all controller actions.

How do I add authentication and authorization hooks to Rails API controllers?

Authentication and authorization in Rails API controllers are implemented using before_action hooks. This secures endpoint access by verifying requests before they reach the controller action.

How do I build new endpoints under Api::V1 in Rails?

Building new endpoints under Api::V1 requires constructing a controller skeleton that follows project conventions. This includes setting up frontmatter, authentication hooks, and delegating to service objects.

Can I use service objects with existing Rails controllers across typical resources?

Yes, you can update existing Rails controllers to delegate business logic to service objects. This applies to standard create, show, update, and destroy actions across typical resources.

When should I refactor a Rails controller to use service objects?

You should refactor a Rails controller to use service objects when it becomes bloated with business logic. Moving this logic keeps the controller focused on handling API requests and responses.