Hello All.
I used the phx.gen.live generator to scaffold up a context and table, etc.
I also have auth in the application (based on phx.gen.auth).
I put the generated live routes in the :require_authenticated_user
pipeline. The generator gives me a :show live_view, and links to that live_view in the :index template
<span><%= live_redirect "Show", to: Routes.boat_show_path(@socket, :show, boat) %></span>
The call is handled in the :show live_view in handle_params :
def handle_params(%{"id" => id}, _, socket) do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:boat, Structures.get_boat!(id))}
end
Since I need the current_user in order to authenticate the route, I added it to the socket (assign_current_user is in the live_helpers.ex file — using the assign_new function) in the mount.
def mount(_params, session, socket) do
socket = assign_current_user(socket, session)
{:ok, socket}
end
I get a KeyError stating it cannot find the specfic record:
##### KeyError <small>at GET</small> <small>/boats/1</small>
# key :boat not found in: %{__changed__: %{current_uri_path: true, current_user: true}, current_uri_path: "/boats/1", current_user: #Baseline.Accounts.User<__meta__: #Ecto.Schema.Metadata<:loaded, "users">, avatar_url: "/uploads/6ab0c1ff-e501-4c3e-a636-ff60c423cf1f.jpg", bio: nil, confirmed_at: nil, email: "user1@example.com", full_name: "John Doe", id: 1, inserted_at: ~N[2022-06-25 21:36:59], updated_at: ~N[2022-06-25 21:37:48], username: "user_number_1", website: nil, ...>, flash: %{}, live_action: :show, socket: #Phoenix.LiveView.Socket<assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>, endpoint: BaselineWeb.Endpoint, id: "phx-FvwEwArWOvo60Qmi", parent_pid: nil, root_pid: nil, router: BaselineWeb.Router, transport_pid: nil, view: BaselineWeb.BoatLive.Show, ...>}
What am I missing.
All help appreciated; thanks in advance.
DJ