Programming Phoenix LiveView B10.0: Handle_event calls wrong function params_with_user (page 213)

This well named helper function is shown on page 213:

def params_with_user_id(params, %{assigns: %{current_user: current_user}}) do
  params
  |> Map.put("user_id", current_user.id)
end

Next, the partial code for handle_event calls a function named params_with_user:

def handle_event("save", %{"demographic" => demographic_params}, socket) do
  params = params_with_user(demographic_params, socket)
  # ...
end

At the bottom of the page, the complete code for handle_event calls the correct function, params_with_user_id:

def handle_event("save", %{"demographic" => demographic_params}, socket) do
  params = params_with_user_id(demographic_params, socket)
  {:noreply, save_demographic(socket, params)}
end
1 Like

Thanks! This will be fixed in the next release.