I’m trying to test out the new LiveView functionality. I have two questions:
First, when testing out the “LiveUser” functionality from the sample repo in my own project, I get that conn
is not available in my template:
ArgumentError at GET /users/new
assign @conn not available in eex template.
Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.
Available assigns: [:changeset, :count, :session, :socket]
Second, how can I redirect to a non-live view from a live view. For example, my UserLive.New wants to redirect to the non-live resources route. Where can I find conn
for the redirect here?
def handle_event("save", %{"user" => user_params}, socket) do
case Authentication.create_user(user_params) do
{:ok, _user} ->
{
:stop,
socket
|> put_flash(:info, "user created")
|> redirect(to: Routes.user_path(conn, :index)) # where does conn come from?
}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
end
end