diff --git a/priv/templates/phx.gen.live/form.ex b/priv/templates/phx.gen.live/form.ex
index b5c0711f1e..25627a4e3c 100644
--- a/priv/templates/phx.gen.live/form.ex
+++ b/priv/templates/phx.gen.live/form.ex
@@ -7,37 +7,32 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
@impl true
def render(assigns) do
~H"""
-
- <.header>
- <%%= @page_title %>
- <:subtitle>Use this form to manage <%= schema.singular %> records in your database.
-
-
- <.simple_form for={@form} id="<%= schema.singular %>-form" phx-change="validate" phx-submit="save">
-<%= Mix.Tasks.Phx.Gen.Html.indent_inputs(inputs, 8) %>
- <:actions>
- <.button phx-disable-with="Saving...">Save <%= schema.human_singular %>
-
-
-
- <.back navigate={return_path(@return_to.key, @<%= schema.singular %>)}>Back to <%%= @return_to.name %>
-
+ <.header>
+ <%%= @page_title %>
+ <:subtitle>Use this form to manage <%= schema.singular %> records in your database.
+
+
+ <.simple_form for={@form} id="<%= schema.singular %>-form" phx-change="validate" phx-submit="save">
+<%= Mix.Tasks.Phx.Gen.Html.indent_inputs(inputs, 6) %>
+ <:actions>
+ <.button phx-disable-with="Saving...">Save <%= schema.human_singular %>
+
+
+
+ <.back navigate={return_path(@return_to, @<%= schema.singular %>)}>Back
"""
end
@impl true
- def mount(_params, _session, socket) do
- {:ok, socket}
+ def mount(params, _session, socket) do
+ {:ok,
+ socket
+ |> assign(:return_to, return_to(params["return_to"]))
+ |> apply_action(socket.assigns.live_action, params)}
end
- @impl true
- def handle_params(params, _url, socket) do
- socket = assign(socket, :return_to, return_to(params["return_to"]))
- {:noreply, apply_action(socket, socket.assigns.live_action, params)}
- end
-
- defp return_to("show"), do: %{key: "show", name: "<%= schema.singular %>"}
- defp return_to(_), do: %{key: "index", name: "<%= schema.plural %>"}
+ defp return_to("show"), do: "show"
+ defp return_to(_), do: "index"
defp apply_action(socket, :edit, %{"id" => id}) do
<%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id)
@@ -73,7 +68,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.key, <%= schema.singular %>))}
+ |> push_navigate(to: return_path(socket.assigns.return_to, <%= schema.singular %>))}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, form: to_form(changeset))}
@@ -86,7 +81,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.key, <%= schema.singular %>))}
+ |> push_navigate(to: return_path(socket.assigns.return_to, <%= 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 1fba90bf87..7fce16ea06 100644
--- a/priv/templates/phx.gen.live/live_test.exs
+++ b/priv/templates/phx.gen.live/live_test.exs
@@ -32,9 +32,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
|> render_click()
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/new")
- html = render(form_live)
- assert html =~ "New <%= schema.human_singular %>"
- assert html =~ "Back to <%= schema.plural %>"
+ assert render(form_live) =~ "New <%= schema.human_singular %>"
assert form_live
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
@@ -60,9 +58,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
|> render_click()
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/#{<%= schema.singular %>}/edit")
- html = render(form_live)
- assert html =~ "Edit <%= schema.human_singular %>"
- assert html =~ "Back to <%= schema.plural %>"
+ assert render(form_live) =~ "Edit <%= schema.human_singular %>"
assert form_live
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
@@ -106,9 +102,7 @@ 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")
- html = render(form_live)
- assert html =~ "Edit <%= schema.human_singular %>"
- assert html =~ "Back to <%= schema.singular %>"
+ assert render(form_live) =~ "Edit <%= schema.human_singular %>"
assert form_live
|> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs)
diff --git a/test/mix/tasks/phx.gen.live_test.exs b/test/mix/tasks/phx.gen.live_test.exs
index a0c746469a..80a92fec8a 100644
--- a/test/mix/tasks/phx.gen.live_test.exs
+++ b/test/mix/tasks/phx.gen.live_test.exs
@@ -105,10 +105,10 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
assert file =~ ~s(<.input field={@form[:votes]} type="number")
assert file =~ ~s(<.input field={@form[:cost]} type="number" label="Cost" step="any")
assert file =~ """
- <.input
- field={@form[:tags]}
- type="select"
- multiple
+ <.input
+ field={@form[:tags]}
+ type="select"
+ multiple
"""
assert file =~ ~s(<.input field={@form[:popular]} type="checkbox")
assert file =~ ~s(<.input field={@form[:drafted_at]} type="datetime-local")
@@ -119,9 +119,9 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
assert file =~ ~s(<.input field={@form[:secret]} type="text" label="Secret" />)
refute file =~ ~s(