layouts-and-rendering

Guide Rails view rendering, layouts, partials, and Turbo-aware status codes.

5|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/ThinkOodle/rails-skills --skill layouts-and-rendering
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: layouts-and-rendering
Source: https://github.com/ThinkOodle/rails-skills/tree/main/skills/layouts-and-rendering
Command: npx skills add https://github.com/ThinkOodle/rails-skills --skill layouts-and-rendering

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides expert guidance to ensure your Rails application renders views correctly, efficiently, and with the appropriate HTTP responses, preventing common errors like "double render" and ensuring seamless integration with Turbo/Hotwire.

Core Features & Use Cases

  • Render vs. Redirect: Clearly distinguishes between render and redirect_to for correct request handling.
  • Partials & Locals: Enforces best practices for partials, emphasizing explicit local variable passing to avoid coupling.
  • Layout Management: Covers layout selection, inheritance, and nested layouts.
  • Turbo/Hotwire Status Codes: Ensures correct HTTP status codes (422, 303) for Turbo-aware responses.
  • Use Case: When building a form that can be edited or created, this Skill helps you correctly handle both successful submissions (redirecting with 303) and validation errors (re-rendering the form with 422), ensuring a smooth user experience with Turbo.

Quick Start

Use the layouts-and-rendering skill to correctly render a form with validation errors, ensuring the form data is preserved and the correct HTTP status code is used.

Frequently Asked Questions about layouts-and-rendering

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

FAQPage Schema
How do I render a Rails partial with local variables correctly?

Rails partials should explicitly pass local variables to avoid coupling with controller instance variables. This practice ensures partials remain reusable, independent components that receive data directly through the render call.

What is the difference between render and redirect_to in Rails?

The difference between render and redirect_to in Rails is that render generates a response from a template within the same request, while redirect_to triggers a new HTTP request. Using both in one action causes a double render error.

What HTTP status codes do I need for Turbo and Hotwire form submissions in Rails?

For Turbo and Hotwire form submissions in Rails, you need a 303 status code for successful redirects and a 422 status code for validation errors. These status codes ensure Turbo correctly processes form re-rendering and navigation.

How do I use content_for and yield for nested layouts in Rails views?

You use content_for and yield for nested layouts in Rails views by defining content blocks in child templates and capturing them with provide. This mechanism allows parent layouts to insert specific content into designated sections.

What is the best way to optimize rendering collections in Rails?

The best way to optimize rendering collections in Rails is to use collection rendering with partials. This approach automatically iterates through records and renders a partial for each item, reducing template code and improving performance.

Why am I getting a double render error in my Rails controller action?

A double render error in a Rails controller action occurs when you call render or redirect_to multiple times in a single request cycle. You must ensure only one rendering instruction is executed per action flow.