Skip to main content
skill CX Codex

alba-inertia — Claude Code skill: what it does, how to install

Configures Alba serializers and Typelizer for Inertia Rails. Generates TypeScript types and replaces as_json with typed Ruby resources.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add inertia-rails/skills --skill alba-inertia -a claude-code
Open on GitHub

What alba-inertia does

The skill guides your agent to structure Inertia Rails props using alba, typelizer, and alba-inertia gems. It splits serialization into entity resources for reusable models, action-specific page resources like UsersIndexResource, and shared props.

When loaded, this skill overrides standard render inertia: { ... } calls in favor of convention-based instance variable rendering. A variable like @users in a controller action gets serialized automatically. It also maps Inertia prop parameters (:defer, :optional, :once, merge) directly onto Alba attributes.

Your project must include alba, typelizer, and alba-inertia in its Gemfile. Without explicit typelize_from declarations on non-matching resource names, Typelizer emits unknown for TypeScript types.

What it helps with

  • Replace untyped as_json calls with structured Alba resources
  • Generate TypeScript definitions from Ruby models automatically
  • Configure deferred, merged, or optional Inertia props inside serializers
  • Organize session and auth data in a dedicated SharedPropsResource

Example prompts for the agent

  • Create an Alba UserResource with Typelizer support for Inertia
  • Set up UsersIndexResource for the controller action using convention rendering
  • Add a deferred prop attribute using the inertia option in our stats resource

How to install alba-inertia

1Skills CLI (Vercel)

npx skills add inertia-rails/skills --skill alba-inertia -a claude-code

2Manually: put the files in place

~/.claude/skills/alba-inertia/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/alba-inertia/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about alba-inertia

How to install alba-inertia in Claude Code?

Run npx skills add inertia-rails/skills --skill alba-inertia -a claude-code in your terminal.

What does alba-inertia do?

It integrates Alba serializers and Typelizer into Inertia Rails applications. It replaces as_json calls with structured resources and generates TypeScript definitions directly from Ruby models.

Why does Typelizer output unknown types?

Typelizer cannot infer column types when the resource name differs from the Rails model. Adding typelize_from ModelName inside the resource class resolves the issue.

Source text

SKILL.md · MIT
---
name: alba-inertia
description: >-
  Alba serializers + Typelizer for type-safe Inertia Rails props with auto-generated TypeScript types. Use when
  serializing models for Inertia responses, setting up Alba resources, generating TypeScript types from Ruby, or
  using Inertia prop options (defer, once, merge, scroll) with Alba attributes. Replaces as_json with structured,
  auto-typed ApplicationResource, page resources, and shared props resources. When active, OVERRIDES the
  `render inertia: { ... }` pattern from other skills — use convention-based instance variable rendering instead.
---

# Alba + Typelizer for Inertia Rails

Requires: `alba`, `typelizer`, `alba-inertia` gems in Gemfile.

Alba serializers for Inertia props with auto-generated TypeScript types.
Replaces `as_json(only: [...])` with structured, type-safe resources.

**Before creating a resource, ask:**
- **Reusable data shape (user, course)?** → Entity resource (`UserResource`) — shared across pages
- **Page-specific props bundle?** → Page resource (`UsersIndexResource`) — one per controller action
- **Global data (auth, notifications)?** → Shared props resource (`SharedPropsResource`)

**NEVER:**
- Use `as_json` when Alba is set up — it bypasses type generation and creates untyped props
- Skip `typelize_from` when resource name differs from model — Typelizer can't infer column types and generates `unknown`
- Put `declare module` augmentations in `serializers/index.ts` — Typelizer-generated types go in `serializers/index.ts`, manual InertiaConfig goes in `globals.d.ts`

## Setup

### ApplicationResource (all resources inherit from this)

```ruby
# app/resources/application_resource.rb
class ApplicationResource
  include Alba::Resource

  helper Typelizer::DSL          # enables typelize, typelize_from
  helper Alba::Inertia::Resource # enables inertia: option on attributes

  include Rails.application.routes.url_helpers
end
```

### Controller Integration

```ruby
# app/controllers/inertia_controller.rb
class InertiaController < ApplicationController
  include Alba::Inertia::Controller

  inertia_share { SharedPropsResource.new(self).to_inertia }
end
```

## Resource Types

### Entity Resource (reusable data shape)

```ruby
# app/resources/user_resource.rb
class UserResource < ApplicationResource
  typelize_from User  # needed when resource name doesn't match model

  attributes :id, :name, :email

  typelize :string?
  attribute :avatar_url do |user|
    user.avatar.attached? ? rails_blob_path(user.avatar, only_path: true) : nil
  end
end
```

### Page Resource (page-specific props)

```ruby
# app/resources/users/index_resource.rb
# Naming convention: {Controller}{Action}Resource
class UsersIndexResource < ApplicationResource
  has_many :users, resource: UserResource

  typelize :string
  attribute :search do |obj, _|
    obj.params.dig(:filters, :search)
  end
end
```

### Shared Props Resource

Requires Rails `Current` attributes (e.g., `Current.user`) to be configured —
see [CurrentAttributes](https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html).

```ruby
# app/resources/shared_props_resource.rb
class SharedPropsResource < ApplicationResource
  one :auth, source: proc { Current }

  attribute :unread_messages_count, inertia: { always: true } do
    Current.user&.unread_count || 0
  end

  has_many :live_now, resource: LiveSessionsResource,
    inertia: { once: { expires_in: 5.minutes } }
end
```

## Convention-Based Rendering

With `Alba::Inertia::Controller`, instance variables auto-serialize:

```ruby
class UsersController < InertiaController
  def index
    @users = User.all        # auto-serialized via UserResource
    @filters = filter_params  # plain data passed through
    # Auto-detects UsersIndexResource
  end

  def show
    @user = User.find(params[:id])
    # Auto-detects UsersShowResource
  end
end
```

## Typelizer + Type Generation

`typelize_from` tells Typelizer which model to infer column types from — needed when
resource name doesn't match model. For computed attributes, declare types explicitly:

```ruby
class AuthorResource < ApplicationResource
  typelize_from User

  attributes :id, :name, :email

  typelize :string?                                  # next attribute is string | undefined
  attribute :avatar_url do |user|
    rails_storage_proxy_path(user.avatar) if user.avatar.attached?
  end

  typelize filters: "{category: number}"            # inline TS type
end
```

Types auto-generate when Rails server runs. Manual: `bin/rake typelizer:generate`.

## Inertia Prop Options in Alba

The `inertia:` option on attributes/associations maps to `InertiaRails` prop types:

```ruby
attribute :stats, inertia: :defer           # InertiaRails.defer
has_many :users, inertia: :optional         # InertiaRails.optional
has_many :countries, inertia: :once         # InertiaRails.once
has_many :items, inertia: { merge: true }   # InertiaRails.merge
attribute :csrf, inertia: { always: true }  # InertiaRails.always
```

**MANDATORY — READ ENTIRE FILE** when using grouped defer, merge with `match_on`,
scroll props, or combining multiple options:
[`references/prop-options.md`](references/prop-options.md) (~60 lines) — full syntax
for all `inertia:` option variants and `inertia_prop` alternative syntax.

**Do NOT load** for basic `inertia: :defer`, `inertia: :optional`, or
`inertia: :once` — the shorthand above is sufficient.

## Troubleshooting

| Symptom | Cause | Fix |
|---------|-------|-----|
| TypeScript type is all `unknown` | Missing `typelize_from` | Add `typelize_from ModelName` when resource name doesn't match model |
| `inertia:` option has no effect | Missing helper | Ensure `helper Alba::Inertia::Resource` is in `ApplicationResource` |
| Types not regenerating | Server not running | Typelizer watches files in dev only. Run `bin/rake typelizer:generate` manually |
| `NoMethodError` for `typelize` | Missing helper | Ensure `helper Typelizer::DSL` is in `ApplicationResource` |
| Convention-based rendering picks wrong resource | Naming mismatch | Resource must be `{Controller}{Action}Resource` (e.g., `UsersIndexResource` for `UsersController#index`) |
| `to_inertia` undefined | Missing include | Controller needs `include Alba::Inertia::Controller` |

## Related Skills
- **Prop types** → `inertia-rails-controllers` (defer, once, merge, scroll)
- **TypeScript config** → `inertia-rails-typescript` (InertiaConfig in globals.d.ts)

© inertia-rails · MIT · inertia-rails/skills

Similar skills

All skills for Backend and APIs →

From the same set9

inertia-rails-architecture Sets the server-driven patterns for Rails + Inertia.js + React and routes you to the right companion skill when you build a page, form or CRUD. CX Codex +1 537installs inertia-rails-pages A skill for building Inertia Rails pages: persistent layouts, Link and router navigation, URL-driven state, deferred sections and infinite scroll. CX Codex +1 504installs inertia-rails-controllers Tells the agent how to return data from Rails controllers to Inertia.js: render inertia, prop types, shared data, flash and validation errors. CX Codex +1 491installs inertia-rails-forms A skill for building forms in Inertia.js + Rails: create, edit, delete, multi-step wizards and file uploads. Useful when wiring form submission to Rails controllers. CX Codex +1 486installs inertia-rails-typescript Configures TypeScript type safety for Inertia Rails with React, Vue, and Svelte. Fixes common TS2344 and TS2339 compiler errors. CX Codex +1 468installs inertia-rails-testing A skill that tells your agent how to test Inertia Rails responses with RSpec and Minitest matchers instead of raw JSON checks. CX Codex +1 465installs shadcn-inertia Adapts shadcn/ui components for Inertia.js Rails React applications instead of Next.js. Guides form wiring, dialogs, and dark mode without react-hook-form. CX Codex +1 432installs inertia-rails-setup Detects your frontend framework and backend gems in an Inertia Rails project, offers missing dependencies, and writes instructions into CLAUDE.md. CX Codex +1 419installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor