mix ash_form_builder.gen.live (AshFormBuilder v0.3.0)

View Source

Scaffolds a complete, production-grade CRUD LiveView interface for the given Ash resource. Generates two files:

  • index.ex — Phoenix LiveView with mount, handle_params, handle_info, and handle_event for full CRUD. URL-state is managed by Cinder.UrlSync.
  • index.html.heex — HEEx template using Cinder.collection for the data table (filtering, sorting, pagination) and AshFormBuilder.FormComponent inside <.modal> for create/edit.

Usage

$ mix ash_form_builder.gen.live Accounts User
$ mix ash_form_builder.gen.live Blog Post
$ mix ash_form_builder.gen.live Inventory Product --page-size 50
$ mix ash_form_builder.gen.live Accounts User --out lib/my_app_web/live/admin

Arguments

  • Context — The Ash domain/context namespace (e.g. Accounts, Blog)
  • Resource — The resource module name within that context (e.g. User, Post)

The full resource module is derived as <AppModule>.<Context>.<Resource>, e.g. mix ash_form_builder.gen.live Accounts UserMyApp.Accounts.User.

Options

  • --out / -o — Override output directory. Default: lib/<otp_app>_web/live/<snake_resource>_live
  • --page-size / -p — Cinder page size. Default: 25

What is Generated

index.ex

defmodule MyAppWeb.UserLive.Index do
  use MyAppWeb, :live_view
  use Cinder.UrlSync

  # mount/3          — initialises assigns (url_state: false, record: nil, form: nil)
  # handle_params/3  — delegates URL state to Cinder.UrlSync, routes live_actions
  # apply_action/3   — builds AshPhoenix.Form for :new and :edit, loads record for :edit
  # handle_info/2    — closes modal + refreshes Cinder table after form submit
  # handle_event/3   — "delete" handler with Cinder refresh
end

index.html.heex

<.header>Users <:actions>New User</:actions></.header>

<Cinder.collection id="user-collection" resource={MyApp.Accounts.User} ...>
  <:col .../>  <%!-- TODO: replace placeholder with real attributes --%>
  <:col label="Actions">Edit | Delete</:col>
</Cinder.collection>

<.modal :if={@live_action in [:new, :edit]} ...>
  <.live_component module={AshFormBuilder.FormComponent} form={@form} resource={...} />
</.modal>

Router Instructions

The generator prints the exact live route entries to add to your router.ex.

Customising Columns

After generation, open index.html.heex and replace the placeholder <:col> with your resource's actual attributes:

<:col :let={user} field="name"   filter sort>{user.name}</:col>
<:col :let={user} field="email"  filter>{user.email}</:col>
<:col :let={user} field="role"   filter={:select}>{user.role}</:col>

Use filter for text filtering, filter={:select} for enum/select filtering, and sort to enable column sorting.