diff --git a/priv/templates/phx.gen.live/form.ex b/priv/templates/phx.gen.live/form.ex index dcc121e97f..b5c0711f1e 100644 --- a/priv/templates/phx.gen.live/form.ex +++ b/priv/templates/phx.gen.live/form.ex @@ -20,7 +20,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web - <.back navigate={~p"<%= schema.route_prefix %>"}>Back to <%= schema.plural %> + <.back navigate={return_path(@return_to.key, @<%= schema.singular %>)}>Back to <%%= @return_to.name %> """ end @@ -36,8 +36,8 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web {:noreply, apply_action(socket, socket.assigns.live_action, params)} end - defp return_to("show"), do: "show" - defp return_to(_), do: "index" + defp return_to("show"), do: %{key: "show", name: "<%= schema.singular %>"} + defp return_to(_), do: %{key: "index", name: "<%= schema.plural %>"} defp apply_action(socket, :edit, %{"id" => id}) do <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) @@ -73,7 +73,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web {:noreply, socket |> put_flash(:info, "<%= schema.human_singular %> updated successfully") - |> push_navigate(to: return_path(socket.assigns.return_to, <%= schema.singular %>))} + |> push_navigate(to: return_path(socket.assigns.return_to.key, <%= schema.singular %>))} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, form: to_form(changeset))} @@ -86,7 +86,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web {:noreply, socket |> put_flash(:info, "<%= schema.human_singular %> created successfully") - |> push_navigate(to: return_path(socket.assigns.return_to, <%= schema.singular %>))} + |> push_navigate(to: return_path(socket.assigns.return_to.key, <%= schema.singular %>))} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, form: to_form(changeset))} diff --git a/priv/templates/phx.gen.live/live_test.exs b/priv/templates/phx.gen.live/live_test.exs index 7fce16ea06..1fba90bf87 100644 --- a/priv/templates/phx.gen.live/live_test.exs +++ b/priv/templates/phx.gen.live/live_test.exs @@ -32,7 +32,9 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web |> render_click() |> follow_redirect(conn, ~p"<%= schema.route_prefix %>/new") - assert render(form_live) =~ "New <%= schema.human_singular %>" + html = render(form_live) + assert html =~ "New <%= schema.human_singular %>" + assert html =~ "Back to <%= schema.plural %>" assert form_live |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs) @@ -58,7 +60,9 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web |> render_click() |> follow_redirect(conn, ~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}/edit") - assert render(form_live) =~ "Edit <%= schema.human_singular %>" + html = render(form_live) + assert html =~ "Edit <%= schema.human_singular %>" + assert html =~ "Back to <%= schema.plural %>" assert form_live |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs) @@ -102,7 +106,9 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web |> render_click() |> follow_redirect(conn, ~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}/edit?return_to=show") - assert render(form_live) =~ "Edit <%= schema.human_singular %>" + html = render(form_live) + assert html =~ "Edit <%= schema.human_singular %>" + assert html =~ "Back to <%= schema.singular %>" assert form_live |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)