skills/rails-views-patterns/SKILL.md
Analyzes Rails view templates, partials, layouts, helpers, and form patterns for best practices. Use when reviewing ERB templates, improving view performance with fragment caching, fixing form helpers, organizing partials, adding accessibility attributes, or evaluating collection rendering. NOT for Stimulus/Turbo logic (use hotwire-patterns), controller concerns, or API-only responses.
npx skillsauth add ag0os/rails-dev-plugin rails-views-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Follow standard Rails view conventions for ERB templates, partials, layouts, helpers, form_with, and content_for regions. This skill covers only the opinionated and non-obvious additions.
Applies on the html delivery axis (Axis B, rails-stack-profiles). On the api axis there are no app views — use rails-api-patterns instead.
See patterns.md for detailed examples.
| Area | Key Rule | Anti-Pattern |
|------|----------|--------------|
| Partials | Extract reusable components | Duplicated HTML across views |
| Collections | Always use render collection: | Manual loops with each |
| Caching | Fragment cache expensive renders | No caching on collection renders |
| Accessibility | Semantic HTML + ARIA | <div> soup without roles |
| Logic | Presenter or helper for complex logic | Conditionals in templates |
<header>, <nav>, <main>, <article>, <section>, <aside> instead of generic <div> wrappersrender collection: -- never each + render inside the loop (performance + enables collection caching)cached: true on collections, Russian-doll nesting for parent/childWhere complex view logic goes is governed by an orthogonal project fact, not an architecture axis: whether the view_component gem is installed. Read it from the project-conventions fingerprint (Frontend category).
view_component gem present: use ViewComponents — see patterns.md.view_component gem: extract complex view logic into plain Ruby presenter objects.# app/presenters/dashboard_presenter.rb
class DashboardPresenter
attr_reader :user, :period
def initialize(user:, period: Date.current.all_month)
@user = user
@period = period
end
def grouped_activities
user.activities.where(date: period).group_by(&:category).sort_by { |cat, _| cat.position }
end
def empty? = user.activities.where(date: period).none?
def title = "#{user.name}'s Dashboard"
end
<%# Clean view -- no logic %>
<h1><%= @presenter.title %></h1>
<% @presenter.grouped_activities.each do |category, activities| %>
<%= render partial: "activity", collection: activities, cached: true %>
<% end %>
| Bad | Good | Why |
|-----|------|-----|
| <% @users = User.all %> in view | Pass @users from controller | Views must not query |
| <% if user.admin? && user.active? && ... %> | Extract to helper or presenter | Logic belongs elsewhere |
| <% @products.each do \|p\| %> + render | render partial:, collection: | Performance + caching |
| <div onclick="..."> | Stimulus controller | Unobtrusive JS |
alt attributes (empty alt="" for decorative images)<label> elements (not just placeholder text)role="navigation", role="main", etc.)<body>aria-describedby and announced with role="alert"aria-live="polite" regionWhen reporting on view quality, use:
## View Analysis: [file_path]
**Issues Found:**
- [severity] description -- suggested fix
**Recommendations:**
1. actionable recommendation
2. ...
development
WHAT: Language-agnostic corrective guidance for the refactoring phase. WHEN: Agent is restructuring code, fixing code smells, reducing complexity, or improving maintainability. NOT FOR: Writing new features, debugging runtime errors, performance tuning, or object design decisions.
testing
Analyzes Rails test suites and recommends testing best practices for RSpec and Minitest. Use when writing new tests, reviewing test coverage, fixing flaky tests, improving test performance, choosing between test types (unit, integration, system, request), or setting up factories and fixtures. NOT for production monitoring, deployment verification, or load/stress testing infrastructure.
development
Detects a Rails project's architecture axes — logic placement (native vs extracted) and delivery (html vs api) — so other skills load profile-appropriate guidance without inline conditionals. Use when planning architecture or when a recommendation depends on where business logic lives or whether the app renders HTML or serves JSON. NOT for test framework, job backend, cache store, or auth library choices — those are orthogonal facts detected by project-conventions.
data-ai
Action Mailer patterns for Rails applications. Automatically invoked when working with email delivery, mailer classes, email templates, mailer previews, interceptors, or delivery configuration. Triggers on "mailer", "email", "ActionMailer", "deliver_later", "deliver_now", "mail template", "email preview", "SMTP", "SendGrid", "Postmark", "notification email". NOT for push notifications, SMS, or in-app messaging.