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.
- 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.
- 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"
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)
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 |
|
|
1---2name: inertia-rails3description: Build Rails + Inertia.js applications from scratch through production. Full lifecycle - setup, pages, forms, validation, shared data, authentication. Covers React/Vue/Svelte frontends with Vite bundling. Includes cookbook for shadcn/ui, modals, meta tags, and error handling.4---56<essential_principles>7## How Inertia Rails Works89Inertia 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.1011### 1. Server-Driven Architecture1213Controllers render Inertia responses instead of views. Data flows from Rails to JavaScript components as props:14```ruby15render inertia: 'Users/Show', props: { user: user.as_json }16```1718### 2. No Client-Side Routing1920Routes 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.2122### 3. Convention-Based Component Resolution2324By default, `render inertia: { user: }` in `UsersController#show` renders `app/frontend/pages/users/show.(jsx|vue|svelte)`. Override with explicit component names when needed.2526### 4. Validation via Redirects2728Unlike typical SPAs returning 422 JSON responses, Inertia follows traditional Rails patterns:291. Controller validates and redirects back on failure302. Errors are flashed and shared as props313. Form state is preserved automatically3233### 5. Shared Data Pattern3435Use `inertia_share` in controllers to provide data to all pages (current_user, flash messages, notifications). Data is included in every response—use sparingly.36</essential_principles>3738<intake>39**What would you like to do?**40411. Set up Inertia in a Rails project422. Create a new page/component433. Build a form with validation444. Add shared data (auth, flash, etc.)455. Handle redirects and navigation466. Debug an Inertia issue477. Test an Inertia controller488. Optimize with partial reloads499. Something else5051**Wait for response before proceeding.**52</intake>5354<routing>55| Response | Workflow |56|----------|----------|57| 1, "setup", "install", "start", "new" | `workflows/setup-inertia.md` |58| 2, "page", "component", "create", "render" | `workflows/create-page.md` |59| 3, "form", "validation", "submit", "useForm" | `workflows/build-form.md` |60| 4, "shared", "auth", "flash", "current_user" | `workflows/shared-data.md` |61| 5, "redirect", "navigate", "link", "router" | `workflows/navigation.md` |62| 6, "debug", "fix", "error", "not working" | `workflows/debug-inertia.md` |63| 7, "test", "spec", "minitest", "rspec" | `workflows/testing.md` |64| 8, "partial", "reload", "optimize", "only" | `workflows/partial-reloads.md` |65| 9, other | Clarify, then select workflow or references |6667**After reading the workflow, follow it exactly.**68</routing>6970<verification_loop>71## After Every Change72731. **Does the page render?** Check Rails logs for Inertia response742. **Are props received?** Console.log props in component753. **Does navigation work?** Click links - should not full-reload764. **Do forms submit?** Check Network tab for XHR requests775. **Are errors displayed?** Test validation failures7879```ruby80# Rails debug - check response type81render inertia: 'Page', props: { debug: true }82```8384```javascript85// Frontend debug - log all props86console.log(usePage().props)87```8889Report to the user:90- "Inertia response: ✓"91- "Props received: X keys"92- "Navigation: SPA mode ✓/✗"93- "Ready for testing"94</verification_loop>9596<reference_index>97## Domain Knowledge9899All in `references/`:100101**Core:** setup.md, responses.md, forms.md, validation.md102**Data Flow:** shared-data.md, links.md103**Quality:** testing.md104**Cookbook:** cookbook.md (shadcn/ui, Inertia Modal, meta tags, error types)105</reference_index>106107<workflows_index>108## Workflows109110All in `workflows/`:111112| File | Purpose |113|------|---------|114| setup-inertia.md | Install and configure Inertia Rails |115| create-page.md | Build new pages with props |116| build-form.md | Forms with validation and useForm |117| shared-data.md | Share auth/flash across all pages |118| navigation.md | Links, redirects, router methods |119| debug-inertia.md | Find and fix Inertia issues |120| testing.md | Test Inertia controllers |121| partial-reloads.md | Optimize with selective data loading |122</workflows_index>