On page 179:
defp assign_demographic
(%{assigns: %{current_user: current_user}} = socket) do
assign(socket, :demographic, %Demographic{user_id: current_user.id})
end
however on page 180 - 181:
<%= if @demographic do %>
<DemographicLive.Show.details demographic={@demographic} />
<% else %>
<.live_component module={DemographicLive.Form} id="demographic-form" user={@current_user} />
<% end %>
The problem here is that when navigating to /survey with a user without demographic info, the assigns will contain user due to the above: user={@current_user} while assign_demographic function expects current_user to be in there instead.
Separately - earlier up on page 180, the code for form.html.heex contains:
phx_target={@myself}
That’s slightly confusing - is it a typo? Perhaps it should be phx-target={@myself}
But then later on there’s a problem intentionally caused by this and instructions to do the following:
for={@changeset}
phx-change="validate"
phx-submit="save"
phx-target={@myself}> <! add this line -->
It would be clearer if the original phx_target={@myself} was omitted altogether on page 180.