inertia-rails-setup
Skill38 starsChanged 8 months agoMITView on GitHub
Set up a new Inertia Rails project or add Inertia to an existing Rails application. Use when creating new projects, configuring Inertia, or setting up the development environment with React, Vue, or Svelte.
- Reads credentials
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- inertia-rails/skillstheir own version, first seen Feb 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- inertia-rails/skills★ 68same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- skills/AGENTS.mdAGENTS.md
- skills/inertia-rails-best-practices/references/AGENTS.mdAGENTS.md
- skills/CLAUDE.mdCLAUDE.md
- inertia-rails-authSkill
- inertia-rails-best-practicesSkill
- inertia-rails-cookbookSkill
- inertia-rails-formsSkill
- inertia-rails-performanceSkill
- inertia-rails-ssrSkill
- inertia-rails-testingSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 90
If you prefer starting from scratch or adding Inertia to an existing Rails app:
- Very specific: line 132
Create or update app/views/layouts/application.html.erb:
- Very specific: line 347
All config options can be set via INERTIA_ prefixed env vars:
- Very specific: line 356
If upgrading an existing Inertia.js v2 project:
- Distinctive: line 360
Add these to your Inertia Rails initializer:
- Very specific: line 406
Run npm install to install dependencies.
- Distinctive: line 409
Check browser console for JavaScript errors.
- Very specific: line 412
Ensure you're using render inertia: not render json:.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Inertia Rails Setup
This skill helps you set up Inertia.js in a Ruby on Rails application with your choice of frontend framework.
Recommended: Official Starter Kits
For new projects, the fastest way to get started is cloning an official starter kit. These include authentication, shadcn/ui components, TypeScript, and optional SSR support out of the box.
React Starter Kit (Recommended)
git clone https://github.com/inertia-rails/react-starter-kit myapp
cd myapp
bin/setupIncludes:
- React 19 + TypeScript
- shadcn/ui component library (20+ components)
- User authentication (login, register, password reset)
- Settings pages (profile, password, email, sessions, appearance)
- Multiple layouts (sidebar, header, auth variants)
- Dark mode support
- Kamal deployment config
- Optional SSR support
- Flash messages with Sonner toasts
Vue Starter Kit
git clone https://github.com/inertia-rails/vue-starter-kit myapp
cd myapp
bin/setupSvelte Starter Kit
git clone https://github.com/inertia-rails/svelte-starter-kit myapp
cd myapp
bin/setupCustomizing the Starter Kit
After cloning:
- Rename the app:
# Update config/application.rb module YourAppName class Application < Rails::Application - Update database config:
# Edit config/database.yml with your settings - Remove example pages you don't need:
# Delete from app/frontend/pages/ and corresponding controllers - Add your own pages:
bin/rails generate controller Products index show # Create app/frontend/pages/products/index.tsx - Customize the layout:
- Edit
app/frontend/layouts/app-layout.tsxfor main app - Edit
app/frontend/components/nav-main.tsxfor navigation
- Edit
Alternative: Generator Setup
If you prefer starting from scratch or adding Inertia to an existing Rails app:
Quick Setup
# Create new Rails app (if needed)
rails new myapp --skip-javascript
# Add inertia_rails gem
bundle add inertia_rails
# Run the generator
bin/rails generate inertia:installThe generator will prompt you to select:
- Frontend framework (React, Vue, or Svelte)
- TypeScript support
- Tailwind CSS integration
Manual Setup Steps
1. Add the Gem
# Gemfile
gem 'inertia_rails'bundle install2. Install Vite Rails (if not present)
bundle add vite_rails
bundle exec vite install3. Configure the Root Layout
Create or update app/views/layouts/application.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csp_meta_tag %>
<%= inertia_ssr_head %>
<%= vite_client_tag %>
<%= vite_javascript_tag 'application' %>
</head>
<body>
<%= yield %>
</body>
</html>4. Install Frontend Dependencies
For React:
npm install @inertiajs/react @inertiajs/vite react react-domFor Vue 3:
npm install @inertiajs/vue3 @inertiajs/vite vueFor Svelte:
npm install @inertiajs/svelte @inertiajs/vite svelte5. Configure the Frontend Entry Point
Create app/frontend/entrypoints/application.js:
React:
import { createInertiaApp } from '@inertiajs/react'
import { createRoot } from 'react-dom/client'
import { inertia } from '@inertiajs/vite'
createInertiaApp({
resolve: inertia.resolvePages('../pages'),
setup({ el, App, props }) {
createRoot(el).render(<App {...props} />)
},
})Vue 3:
import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/vue3'
import { inertia } from '@inertiajs/vite'
createInertiaApp({
resolve: inertia.resolvePages('../pages'),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.mount(el)
},
})Svelte:
import { createInertiaApp } from '@inertiajs/svelte'
import { inertia } from '@inertiajs/vite'
createInertiaApp({
resolve: inertia.resolvePages('../pages'),
setup({ el, App }) {
new App({ target: el })
},
})6. Create the Pages Directory
mkdir -p app/frontend/pages7. Configure the Initializer
Create config/initializers/inertia_rails.rb:
# frozen_string_literal: true
InertiaRails.configure do |config|
# Asset versioning
config.version = -> { ViteRuby.digest }
# Flash keys exposed to frontend
config.flash_keys = %i[notice alert]
# Required for Inertia.js v3
config.use_script_element_for_initial_page = true
config.use_data_inertia_head_attribute = true
config.always_include_errors_hash = true
# Deep merge shared data with page props
# config.deep_merge_shared_data = true
# Encrypt history for sensitive data (requires HTTPS)
# config.encrypt_history = Rails.env.production?
end8. Set Up Shared Data
In app/controllers/application_controller.rb:
class ApplicationController < ActionController::Base
inertia_share do
{
flash: {
notice: flash.notice,
alert: flash.alert
},
auth: {
user: current_user&.as_json(only: [:id, :name, :email])
}
}
end
end9. Create Your First Page
Controller:
# app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
render inertia: { message: 'Welcome to Inertia Rails!' }
end
endRoute:
# config/routes.rb
Rails.application.routes.draw do
root 'home#index'
endPage Component (React):
// app/frontend/pages/home/index.jsx
export default function Home({ message }) {
return (
<div>
<h1>{message}</h1>
</div>
)
}Page Component (Vue):
<!-- app/frontend/pages/home/index.vue -->
<script setup>
defineProps(['message'])
</script>
<template>
<div>
<h1>{{ message }}</h1>
</div>
</template>10. Start the Development Servers
# Terminal 1: Rails server
bin/rails server
# Terminal 2: Vite dev server
bin/vite devConfiguration Options Reference
| Option | Default | Description |
version | nil | Asset version for cache busting |
layout | 'application' | Default layout template |
flash_keys | [:notice, :alert] | Flash keys to share |
deep_merge_shared_data | false | Deep merge props |
encrypt_history | false | Encrypt browser history |
ssr_enabled | false | Enable SSR |
ssr_url | 'http://localhost:13714' | SSR server URL |
default_render | false | Auto-render Inertia |
root_dom_id | 'app' | Root element ID |
use_script_element_for_initial_page | false | Use <script> tag for initial page data (required for v3) |
use_data_inertia_head_attribute | false | Use data-inertia attribute for head tags (required for v3) |
always_include_errors_hash | nil | Always include errors object in page props |
prop_transformer | identity | Transform prop keys (e.g., camelCase) |
component_path_resolver | "path/action" | Custom component name resolution |
parent_controller | '::ApplicationController' | Base controller for static routes |
expose_shared_prop_keys | true | Include shared prop keys in page metadata |
precognition_prevent_writes | false | Prevent DB writes during precognition |
Environment Variables
All config options can be set via INERTIA_ prefixed env vars:
INERTIA_SSR_ENABLED=true
INERTIA_ENCRYPT_HISTORY=trueUpgrading to Inertia.js v3
If upgrading an existing Inertia.js v2 project:
Required Configuration Changes
Add these to your Inertia Rails initializer:
config.use_script_element_for_initial_page = true
config.use_data_inertia_head_attribute = true
config.always_include_errors_hash = trueBreaking Changes
- React 19+ required
- Svelte 5+ with runes syntax required
- ES2022 build target required
- ESM-only — no CommonJS
- Axios removed — uses built-in XHR (use
axiosAdapter()to keep Axios) - Event renames:
invalid→httpException,exception→networkError router.cancel()→router.cancelAll()- Head attribute:
inertia→data-inertia
Install the Vite Plugin
npm install @inertiajs/viteUpdate vite.config.js:
import inertia from '@inertiajs/vite'
export default defineConfig({
plugins: [
inertia(),
// ... other plugins
],
})The Vite plugin provides:
- Automatic page component resolution
- Simplified SSR setup (no separate entry point in development)
withAppcallback for providers/plugins
Troubleshooting
"Cannot find module '@inertiajs/react'"
Run npm install to install dependencies.
Blank page with no errors
Check browser console for JavaScript errors. Ensure Vite dev server is running.
Props not updating
Ensure you're using render inertia: not render json:.
CSRF token errors
Inertia handles CSRF automatically. Ensure protect_from_forgery is enabled.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

