inertia-rails-best-practices

Comprehensive best practices for Inertia Rails development. Use when writing, reviewing, or refactoring Inertia.js Rails applications with React, Vue, or Svelte frontends. Covers server-side setup, props management, forms, navigation, performance, security, and testing patterns.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "inertia-rails-best-practices" with this command: npx skills add cole-robertson/inertia-rails-skills/cole-robertson-inertia-rails-skills-inertia-rails-best-practices

Inertia Rails Best Practices

A comprehensive guide to building high-quality Inertia.js applications with Ruby on Rails. This skill provides 50+ rules across 8 categories, prioritized by impact on application quality, performance, and maintainability.

When to Use This Skill

  • Writing new Inertia Rails controllers or pages
  • Reviewing existing Inertia Rails code
  • Refactoring Rails applications to use Inertia
  • Optimizing performance of Inertia applications
  • Implementing authentication/authorization patterns
  • Building forms with validation
  • Setting up testing for Inertia responses

Categories Overview

#CategoryPriorityImpact
1Server-Side Setup & ConfigurationCRITICALFoundation for all Inertia functionality
2Props & Data ManagementCRITICAL2-5× performance improvement, security
3Forms & ValidationHIGHUser experience, data integrity
4Navigation & RoutingHIGHSPA experience, performance
5Performance OptimizationMEDIUM-HIGH30-70% faster page loads
6SecurityMEDIUM-HIGHProtection against common vulnerabilities
7TestingMEDIUMCode quality, maintainability
8Advanced PatternsMEDIUMScalability, complex use cases

Quick Reference

Server-Side Setup & Configuration (CRITICAL)

IDRuleContext
setup-01Use the Rails generator for initial setupNew projects
setup-02Configure asset versioning for cache bustingAll projects
setup-03Set up proper layout inheritanceMulti-layout apps
setup-04Configure flash keys appropriatelyFlash messaging
setup-05Use environment variables for configurationDeployment
setup-06Set up default render behavior thoughtfullyConvention over configuration

Props & Data Management (CRITICAL)

IDRuleContext
props-01Return only necessary data in propsAll responses
props-02Use shared data for global propsAuth, settings
props-03Leverage lazy evaluation with lambdasExpensive operations
props-04Use deferred props for non-critical dataPerformance
props-05Implement partial reloads correctlyData refreshing
props-06Never expose sensitive data in propsSecurity
props-07Use proper serialization with as_jsonData formatting
props-08Implement deep merge when appropriateNested data
props-09Use once props for stable dataNavigation performance

Forms & Validation (HIGH)

IDRuleContext
forms-01Use useForm helper for complex formsProgrammatic control
forms-02Use Form component for simple formsDeclarative forms
forms-03Handle validation errors properlyUser feedback
forms-04Implement error bags for multiple formsMulti-form pages
forms-05Use redirect pattern after form submissionPRG pattern
forms-06Handle file uploads correctlyMultipart forms
forms-07Preserve form state on validation errorsUser experience
forms-08Use dotted notation for nested dataComplex forms

Navigation & Routing (HIGH)

IDRuleContext
nav-01Use Link component for internal navigationSPA behavior
nav-02Use inertia_location for external redirectsExternal URLs
nav-03Implement preserve-scroll appropriatelyScroll position
nav-04Use preserve-state for component stateForm preservation
nav-05Configure proper HTTP methods on linksRESTful actions
nav-06Use the inertia route helper for static pagesSimple routes
nav-07Handle 303 redirects correctlyPOST/PUT/PATCH/DELETE

Performance Optimization (MEDIUM-HIGH)

IDRuleContext
perf-01Implement code splitting with dynamic importsBundle size
perf-02Use prefetching for likely navigationPerceived performance
perf-03Configure stale-while-revalidate cachingData freshness
perf-04Use polling only when necessaryReal-time updates
perf-05Implement infinite scrolling with merge propsLarge datasets
perf-06Optimize progress indicatorsUser feedback
perf-07Use async visits for non-blocking operationsBackground tasks

Security (MEDIUM-HIGH)

IDRuleContext
sec-01Implement authentication server-sideAuth patterns
sec-02Pass authorization results as propsPermission checks
sec-03Use history encryption for sensitive dataBrowser history
sec-04Rely on Rails CSRF protectionForm security
sec-05Validate and sanitize all input server-sideData validation
sec-06Use strong parameters in controllersMass assignment

Testing (MEDIUM)

IDRuleContext
test-01Use RSpec matchers for Inertia responsesRSpec testing
test-02Use Minitest assertions for InertiaMinitest testing
test-03Test partial reloads and deferred propsAdvanced features
test-04Implement end-to-end tests with CapybaraIntegration testing
test-05Test flash messages after redirectsFlash testing
test-06Verify component renderingResponse validation

Advanced Patterns (MEDIUM)

IDRuleContext
adv-01Implement persistent layoutsState preservation
adv-02Use custom component path resolversNon-standard paths
adv-03Configure prop transformersData transformation
adv-04Handle SSR appropriatelySEO requirements
adv-05Implement view transitionsModern animations
adv-06Use scroll regions for complex layoutsScroll management
adv-07Handle events system effectivelyLifecycle hooks

For detailed explanations, code examples, and implementation guidance for each rule, see AGENTS.md.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

inertia-rails-performance

No summary provided by upstream source.

Repository SourceNeeds Review
General

inertia-rails-forms

No summary provided by upstream source.

Repository SourceNeeds Review
General

inertia-rails-auth

No summary provided by upstream source.

Repository SourceNeeds Review
General

inertia-rails-cookbook

No summary provided by upstream source.

Repository SourceNeeds Review