Skip to content
RailsDev.io

Inertia.js in Rails: React Frontend Without Building a Separate API

Inertia Rails: how to add a React frontend without a separate API, what changes in your controllers and views, and the trade-offs in production.

Diagram of Inertia.js with Rails: a browser requests a page, Rails controllers render React components passed props, no JSON API contract is needed
On this page
  1. The problem Inertia solves
  2. How it works, in one paragraph
  3. Setup sketch (Rails 8, React, Vite)
  4. Inertia vs Hotwire: the honest comparison
  5. Adopting Inertia inside an existing app
  6. Pitfalls that bite in production
  7. Where Inertia is the wrong tool
  8. Conclusion
  9. Frequently asked questions

Inertia Rails (inertia_rails) lets you build a React (or Vue/Svelte) frontend on Rails without building a separate JSON API and without the dual-routing complexity of an SPA. Rails controllers stay Rails controllers: they fetch data, authorise, and render — Inertia swaps the rendered HTML for a React component and a JSON payload of props. As of October 2026, inertia_rails is at 3.23.0.

This guide covers how it works, when it beats Hotwire, how to adopt it inside an existing Rails app, and the trade-offs I see in production.

The problem Inertia solves

Every Rails team hits the same fork: sprinkle interactivity with Hotwire, or commit to a React SPA. The SPA path means a new codebase, an API contract, auth flows you get wrong once, and two deploy pipelines. The Hotwire path is superb for CRUD but awkward when the UI genuinely needs component-state complexity: kanban, editors, dense dashboards.

Inertia sits in between. You keep Rails’ server-side everything — sessions, CSRF, authorization, Active Record, views — and swap view rendering for React components. The client gets SPA navigation and client state; the server keeps validation and permissions.

How it works, in one paragraph

ruby
# app/controllers/orders_controller.rb
def index
  render inertia: 'Orders/Index', props: {
    orders: Order.recent.map { |o| { id: o.id, total: o.total, status: o.status } },
  }
end
tsx
// app/javascript/pages/Orders/Index.tsx
export default function Index({ orders }: Props) {
  return <OrderTable orders={orders} />;
}

No API is published, no fetch client is written, no serialization layer to version. The page is a React app booted with exactly the props your controller decided to send. Navigation intercepts link clicks, requests the next component with its props, and swaps it in — the URL still belongs to Rails.

Setup sketch (Rails 8, React, Vite)

bash
bundle add inertia_rails
bundle add vite_rails vite_plugin_ruby
bin/rails inertia:install
npm install @inertiajs/react

Then wire a layout that boots the client (inertia_rails ships a generator that writes application.html.erb and the Vite entry), declare inertia: true in your layout, and map your routes as usual. The inertia_rails docs cover the React entry point and SSR; read them — the exact wiring has changed between major versions.

Inertia vs Hotwire: the honest comparison

Hotwire Inertia
Language split HTML + a little JS TypeScript/React for all UI logic
Server-side simplicity Maximum High (no API, but controllers pass props)
Client-side interactivity ceiling Moderate Full React ecosystem
SEO Excellent (HTML served) Good (SSR available)
Team skill requirement Rails only Rails + React
Deploy story One app One app, but UI build pipeline exists
Best for Forms, dashboards, content Complex interactive UI inside a Rails product

My comparison of Hotwire vs React covers the underlying trade-off in more depth.

Adopting Inertia inside an existing app

Don’t migrate the whole app at once. The pattern that works:

  1. Start with the one screen where Hotwire is painful — the editor, the planner, the live board.
  2. Add Inertia just for that route; the rest of the app stays ERB/Hotwire.
  3. Share layout and styling (a plain Rails layout with a Vite entry can host both).
  4. Extract components gradually; resist the pull to “rewrite it all in React”.
  5. Keep authorization, validation and business logic in Rails — always.

Pitfalls that bite in production

  • Props bloat: controllers passing the world serialise huge JSON payloads. Send ids and labels the view needs; lazy-load the rest with partial reloads (inertia: { only: [...] }).
  • Validation drift: forms submitted through Inertia still get server validation errors forwarded as props — 422 maps cleanly to field errors. Keep client-side checks cosmetic.
  • Client state duplication: a deep_freeze in the store saves time debugging; never let two sources of truth for “current document” survive.
  • Partial reloads with authorization: ensure every prop respects the same permission checks as a full page.
  • SSR for public pages: for SEO-relevant pages, configure SSR; otherwise serve them as ERB and keep Inertia for authenticated app screens.

Where Inertia is the wrong tool

If your frontend is a static marketing site or mostly Hotwire-friendly CRUD, Inertia is complexity you don’t need. If you have two teams shipping independently against a stable contract, a real API might be better. And if neither React nor Rails is on the table, that’s a different article.

If you want a second pair of eyes on whether Inertia fits a specific flow, send me a short brief — I work on the React + Rails seam daily, including TypeScript and component design, as part of my React and Rails service.

Conclusion

Inertia gives you React’s component model on top of Rails controllers, with no API layer to design, version or defend. Start with the screen where Hotwire hurts most, migrate incrementally, and keep the server as the source of truth throughout — or send me a short brief and I’ll do that with you.

Frequently asked questions

Do we still need JSON:API or jbuilder with Inertia?

No. Inertia replaces the hand-written JSON layer for Inertia pages. Keep jbuilder only if external clients consume the same data.

Does Inertia work with Rails 8?

Yes — inertia_rails 3.x supports current Rails. The gem is actively maintained; check the README for the exact compatibility matrix before upgrading either side.

Can we use Inertia with Vue instead of React?

Yes. Inertia has first-class Vue and Svelte adapters. The Rails side is unchanged; only the client adapter differs.

Is Inertia SEO-friendly?

For search visibility, serve public pages as plain ERB or enable Inertia’s SSR. Authenticated app pages rarely need SEO.

How do forms handle validation errors?

The server renders the same page with error props (or returns 422, which Inertia maps to the same). No client-side reimplementation of model validations is required.

Inertia or a full SPA?

If you have multiple frontends or need an API anyway, a full SPA pays off. If the product is one Rails web app, Inertia gives you most of the benefit with much less machinery.

Keep reading