Agent skill

rails-views-patterns

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.

Stars 4
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/ag0os/rails-dev-plugin/tree/main/skills/rails-views-patterns

SKILL.md

Rails Views Patterns

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.

See patterns.md for detailed examples.

Quick Reference

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

Core Principles

  1. Views are for presentation only -- no queries, no mutations, no business logic
  2. Semantic HTML5 -- use <header>, <nav>, <main>, <article>, <section>, <aside> instead of generic <div> wrappers
  3. Always render collection: -- never each + render inside the loop (performance + enables collection caching)
  4. Cache aggressively -- fragment caching with cached: true on collections, Russian-doll nesting for parent/child

Presenter Objects (Profile-Aware)

Omakase: Extract complex view logic into plain Ruby presenter objects -- not ViewComponents.

ruby
# app/presenters/dashboard_presenter.rb (or app/models/ for omakase)
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
erb
<%# Clean view -- no logic %>
<h1><%= @presenter.title %></h1>
<% @presenter.grouped_activities.each do |category, activities| %>
  <%= render partial: "activity", collection: activities, cached: true %>
<% end %>

Service-oriented: ViewComponents are preferred when the view_component gem is present. See patterns.md for the ViewComponent pattern.

Anti-Patterns

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

Accessibility Checklist

  • All images have meaningful alt attributes (empty alt="" for decorative images)
  • Form fields have associated <label> elements (not just placeholder text)
  • Interactive elements are keyboard-accessible
  • Color contrast meets WCAG AA (4.5:1 for text, 3:1 for large text)
  • ARIA landmarks on major page regions (role="navigation", role="main", etc.)
  • Skip-to-content link as first focusable element in <body>
  • Error messages linked via aria-describedby and announced with role="alert"
  • Flash messages wrapped in aria-live="polite" region

Output Format

When reporting on view quality, use:

## View Analysis: [file_path]

**Issues Found:**
- [severity] description -- suggested fix

**Recommendations:**
1. actionable recommendation
2. ...

Expand your agent's capabilities with these related and highly-rated skills.

ag0os/rails-dev-plugin

rails-caching-patterns

Caching patterns for Rails applications including fragment caching, low-level caching, HTTP caching, Russian doll caching, and cache invalidation strategies. Automatically invoked when working with Rails.cache, cache stores, stale?/fresh_when, fragment caching, cache keys, or performance optimization through caching. Triggers on "cache", "caching", "Rails.cache", "fragment cache", "Russian doll", "stale?", "fresh_when", "cache key", "cache store", "Redis cache", "Solid Cache", "memcached", "ETag", "cache invalidation", "cache bust". NOT for CDN configuration (use rails-devops-patterns) or database query optimization (use rails-model-patterns).

4 0
Explore
ag0os/rails-dev-plugin

rails-graphql-patterns

Analyzes and recommends GraphQL patterns for Rails using graphql-ruby including schema design, types, resolvers, mutations, subscriptions, DataLoader, and query complexity. Use when building GraphQL APIs, defining types, writing mutations, optimizing N+1 queries, or structuring app/graphql. NOT for REST API controllers, ActiveRecord queries outside GraphQL, or Turbo Stream responses.

4 0
Explore
ag0os/rails-dev-plugin

ruby-object-design

Automatically invoked when making decisions about Ruby code structure and organization. Triggers on "class or module", "should this be a class", "struct vs class", "PORO", "data object", "design pattern", "class vs module", "when to use class", "module vs class", "stateless class", "value object", "data container", "object factory", "extend self", "singleton class". Provides guidance on choosing the right Ruby construct (class, module, Struct, Data, Hash). NOT for code smell identification or refactoring (use ruby-refactoring) or Rails-specific framework patterns.

4 0
Explore
ag0os/rails-dev-plugin

rails-architecture-patterns

Provides architectural planning, design decisions, and coordination guidance for Rails applications. Use when planning new features, choosing between design approaches (STI vs polymorphic, service vs concern, monolith vs engine), evaluating system architecture, or deciding which domain skill or agent to delegate to. NOT for implementation details within a single domain (use the domain-specific skill instead).

4 0
Explore
ag0os/rails-dev-plugin

rails-mailer-patterns

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.

4 0
Explore
ag0os/rails-dev-plugin

rails-devops-patterns

Analyzes Rails deployment, infrastructure, and production configuration for best practices. Use when setting up Docker, writing CI/CD pipelines, configuring Puma, adding monitoring or logging, hardening security (SSL, Rack::Attack, headers), optimizing database config, or reviewing production environment files. NOT for application business logic, model design, or test writing.

4 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results