mix phx.gen.live
generates LiveView, templates, and context for a resource. The generator creates two LiveViews, ResourceLive.Index
and ResourceLive.Show
.
ResourceLive.Index
is also used for the new
and edit
actions. ResourceLive.Show
is also used for edit
. All of the forms (new
& edit
) rely on a modal to display to the user. The create
and update
actions are handled in the LiveView as well, but they don’t have routes in the router.
See generated router actions for my InjuredReserve
resource below.
live "/injured_reserves", InjuredReserveLive.Index, :index
live "/injured_reserves/new", InjuredReserveLive.Index, :new
live "/injured_reserves/:id/edit", InjuredReserveLive.Index, :edit
live "/injured_reserves/:id", InjuredReserveLive.Show, :show
live "/injured_reserves/:id/show/edit", InjuredReserveLive.Show, :edit
I don’t plan to use a modal in my app. Is the simplest approach to create a LiveView for both the new
and edit
actions (ResourceLive.New
and ResourceLive.Edit
) then handle the create
and update
actions in those LiveViews?
Any big downsides or gotchas to this approach?