After taking a fresh look, I can clarify my question about the generator:
The generator creates Lifeviews to list, show, edit and delete artists.
AND it create a LiveComponent == FormLive to do the actual editing.
My question is about this Component. Why isn’t it a normal LV?
In the Tunez-App in your book you are using a LiveView == FormLive, which is the way, I would have done it. So the question was: Why is the generator not doing the same??
That way I had to convert the LV-Code of the book to my LiveComponent.
Otherwise it would have been easy-peasy.
But I learned a lot by doing so. ![]()
I also ran into one problem which I don’t understand:
The book-code of FormLive looks like this:
def mount(%{"id" => album_id}, _session, socket) do
album = Tunez.Music.get_album_by_id!(album_id, load: [:artist])
form = Tunez.Music.form_to_update_album(album)
So I converted that to:
defp assign_form(%{assigns: %{album: album}} = socket) do
if album do
artist = Tuneshg.Music.get_artist_by_id!(album.artist_id)
form = Tuneshg.Music.form_to_update_album(album)
That looked correct, but later, when I tried to edit an album and typed, I got:
[debug] HANDLE EVENT "validate" in TuneshgWeb.AlbumLive.Index
Component: TuneshgWeb.AlbumLive.FormComponent
Parameters: %{"_target" => ["form", "name"], "form" => %{"_unused_artist_id" => "", "_unused_cover_image_url" => "", "_unused_name" => "", "_unused_year_released" => "", "artist_id" => "9ad16706-01f7-4b51-8633-21434ba39f21", "cover_image_url" => "/images/albums/nights_in_the_nullarbor_wild.png", "name" => "Wilde", "year_released" => "2023"}}
[error] GenServer #PID<0.772.0> terminating
** (FunctionClauseError) no function clause matching in TuneshgWeb.AlbumLive.FormComponent.handle_event/3
I modified my code to:
form =
AshPhoenix.Form.for_update(album, :update,
as: "album",
transform_params: fn _form, params, _context ->
Map.put(params, "artist_id", artist.id)
end
)
using AshPhoenix.Form.for_update, that I used before and everything worked again.
I don’t know, why the two methods are not equivalent, but I think you do ![]()
My last point:
Yes, you are right, I am making it harder for me to follow
the code in your book and from chapter 3 on, I decided to accept your proposal and follow the book using the Tunez-Code.
Again, dear Zach, thanks a lot for your patience and your time helping me and explaining so superbly, Heiko






















