--- name: inertia-rails-setup description: 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. license: MIT metadata: author: community version: "1.0.0" user-invocable: true argument-hint: "[react|vue|svelte] [--typescript] [--tailwind]" --- # 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) ```bash git clone https://github.com/inertia-rails/react-starter-kit myapp cd myapp bin/setup ``` **Includes:** - 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 ```bash git clone https://github.com/inertia-rails/vue-starter-kit myapp cd myapp bin/setup ``` ### Svelte Starter Kit ```bash git clone https://github.com/inertia-rails/svelte-starter-kit myapp cd myapp bin/setup ``` ### Customizing the Starter Kit After cloning: 1. **Rename the app:** ```bash # Update config/application.rb module YourAppName class Application < Rails::Application ``` 2. **Update database config:** ```bash # Edit config/database.yml with your settings ``` 3. **Remove example pages you don't need:** ```bash # Delete from app/frontend/pages/ and corresponding controllers ``` 4. **Add your own pages:** ```bash bin/rails generate controller Products index show # Create app/frontend/pages/products/index.tsx ``` 5. **Customize the layout:** - Edit `app/frontend/layouts/app-layout.tsx` for main app - Edit `app/frontend/components/nav-main.tsx` for navigation --- ## Alternative: Generator Setup If you prefer starting from scratch or adding Inertia to an existing Rails app: ### Quick Setup ```bash # 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:install ``` The generator will prompt you to select: - Frontend framework (React, Vue, or Svelte) - TypeScript support - Tailwind CSS integration ## Manual Setup Steps ### 1. Add the Gem ```ruby # Gemfile gem 'inertia_rails' ``` ```bash bundle install ``` ### 2. Install Vite Rails (if not present) ```bash bundle add vite_rails bundle exec vite install ``` ### 3. Configure the Root Layout Create or update `app/views/layouts/application.html.erb`: ```erb
<%= csp_meta_tag %> <%= inertia_ssr_head %> <%= vite_client_tag %> <%= vite_javascript_tag 'application' %> <%= yield %> ``` ### 4. Install Frontend Dependencies **For React:** ```bash npm install @inertiajs/react react react-dom ``` **For Vue 3:** ```bash npm install @inertiajs/vue3 vue ``` **For Svelte:** ```bash npm install @inertiajs/svelte svelte ``` ### 5. Configure the Frontend Entry Point Create `app/frontend/entrypoints/application.js`: **React:** ```javascript import { createInertiaApp } from '@inertiajs/react' import { createRoot } from 'react-dom/client' createInertiaApp({ resolve: (name) => { const pages = import.meta.glob('../pages/**/*.jsx', { eager: true }) return pages[`../pages/${name}.jsx`] }, setup({ el, App, props }) { createRoot(el).render(