inertia-rails
<essential_principles>
How Inertia Rails Works
Inertia is a bridge between Rails and modern JavaScript frameworks (React, Vue, Svelte). It lets you build SPAs using classic server-side routing and controllers—no client-side routing or separate APIs needed.
1. Server-Driven Architecture
Controllers render Inertia responses instead of views. Data flows from Rails to JavaScript components as props:
render inertia: 'Users/Show', props: { user: user.as_json }
2. No Client-Side Routing
Routes live in config/routes.rb. Inertia intercepts link clicks and form submissions, making XHR requests that return JSON with component name and props. The client swaps components without full page reloads.
3. Convention-Based Component Resolution
By default, render inertia: { user: } in UsersController#show renders app/frontend/pages/users/show.(jsx|vue|svelte). Override with explicit component names when needed.
4. Validation via Redirects
Unlike typical SPAs returning 422 JSON responses, Inertia follows traditional Rails patterns:
- Controller validates and redirects back on failure
- Errors are flashed and shared as props
- Form state is preserved automatically
5. Shared Data Pattern
Use inertia_share in controllers to provide data to all pages (current_user, flash messages, notifications). Data is included in every response—use sparingly.
</essential_principles>
- Set up Inertia in a Rails project
- Create a new page/component
- Build a form with validation
- Add shared data (auth, flash, etc.)
- Handle redirects and navigation
- Debug an Inertia issue
- Test an Inertia controller
- Optimize with partial reloads
- Something else
Wait for response before proceeding.
After reading the workflow, follow it exactly.
<verification_loop>
After Every Change
- Does the page render? Check Rails logs for Inertia response
- Are props received? Console.log props in component
- Does navigation work? Click links - should not full-reload
- Do forms submit? Check Network tab for XHR requests
- Are errors displayed? Test validation failures
# Rails debug - check response type
render inertia: 'Page', props: { debug: true }
// Frontend debug - log all props
console.log(usePage().props)
Report to the user:
- "Inertia response: ✓"
- "Props received: X keys"
- "Navigation: SPA mode ✓/✗"
- "Ready for testing" </verification_loop>
<reference_index>
Domain Knowledge
All in references/:
Core: setup.md, responses.md, forms.md, validation.md Data Flow: shared-data.md, links.md Quality: testing.md Cookbook: cookbook.md (shadcn/ui, Inertia Modal, meta tags, error types) </reference_index>
<workflows_index>
Workflows
All in workflows/:
| File | Purpose |
|---|---|
| setup-inertia.md | Install and configure Inertia Rails |
| create-page.md | Build new pages with props |
| build-form.md | Forms with validation and useForm |
| shared-data.md | Share auth/flash across all pages |
| navigation.md | Links, redirects, router methods |
| debug-inertia.md | Find and fix Inertia issues |
| testing.md | Test Inertia controllers |
| partial-reloads.md | Optimize with selective data loading |
| </workflows_index> |
More from faqndo97/ai-skills
kamal-deployment
Deploy containerized applications (especially Rails) to VPS using Kamal 2. Covers deploy.yml configuration, accessories (PostgreSQL, Redis, Sidekiq), SSL/TLS, secrets management, CI/CD with GitHub Actions, database backups, server hardening, debugging, and scaling. Use when setting up Kamal, configuring deployments, troubleshooting deploy issues, or managing production infrastructure with Kamal.
31stimulus
Build Stimulus controllers from scratch through production. Full lifecycle - create, debug, test, optimize, integrate with Turbo. Covers targets, values, actions, outlets, and UI patterns.
22ruby-llm
Build AI-powered Ruby applications with RubyLLM. Full lifecycle - chat, tools, streaming, Rails integration, embeddings, and production deployment. Covers all providers (OpenAI, Anthropic, Gemini, etc.) with one unified API.
20ruby-on-rails
Build Ruby on Rails features from scratch through production. Full lifecycle - build, debug, test, optimize, refactor. Follows Vanilla Rails philosophy (37signals/DHH), SOLID principles, and Rails 8 patterns.
19noticed
Build Rails notifications with the noticed gem. Full lifecycle - create notifiers, configure delivery methods (email, Slack, push, SMS, ActionCable), debug, and test. Covers individual and bulk delivery patterns.
15shadcn-ui
Build production-ready React/Next.js UIs with shadcn/ui components. Full lifecycle - install, customize, compose, debug, optimize. Covers components, forms, tables, theming, animations, and hooks.
14