I hear what you’re saying but I don’t know where to look anymore… I was adding those layouts in several places, I replaced the code in all of them, I was adding them only using this plug and it happens for every template, the moment I update the controller, that layout is not being rendered anymore.
Here’s one of the controllers, most of the code has been generated by phx.gen.auth.
defmodule TestAppWeb.UserSettingsController do
use TestAppWeb, :controller
alias TestApp.Accounts
alias TestAppWeb.UserAuth
plug :assign_email_and_password_changesets
plug :put_layout, [html: {TestAppWeb.LayoutView, :account}] when action in [:edit, :update]
# plug :put_layout, "account.html" when action in [:edit, :update]
def action(conn, _) do
args = [conn, conn.params, conn.assigns.current_user]
apply(__MODULE__, action_name(conn), args)
end
def edit(conn, _params, _current_user) do
IO.inspect layout(conn, :html)
render(conn, "edit.html", page_title: "Settings")
end
def update(conn, %{"action" => "update_email"} = params, current_user) do
%{"current_password" => password, "user" => user_params} = params
case Accounts.apply_user_email(current_user, password, user_params) do
{:ok, applied_user} ->
Accounts.deliver_update_email_instructions(
applied_user,
current_user.email,
&Routes.user_settings_url(conn, :confirm_email, &1)
)
conn
|> put_flash(
:info,
"A link to confirm your email change has been sent to the new address."
)
|> redirect(to: Routes.user_settings_path(conn, :edit))
{:error, changeset} ->
render(conn, "edit.html", page_title: "Settings", email_changeset: changeset)
end
end
def update(conn, %{"action" => "update_password"} = params, _current_user) do
%{"current_password" => password, "user" => user_params} = params
user = conn.assigns.current_user
case Accounts.update_user_password(user, password, user_params) do
{:ok, user} ->
conn
|> put_flash(:info, "Password updated successfully.")
|> put_session(:user_return_to, Routes.user_settings_path(conn, :edit))
|> UserAuth.log_in_user(user)
{:error, changeset} ->
render(conn, "edit.html", password_changeset: changeset)
end
end
def confirm_email(conn, %{"token" => token}, _current_user) do
case Accounts.update_user_email(conn.assigns.current_user, token) do
:ok ->
conn
|> put_flash(:info, "Email changed successfully.")
|> redirect(to: Routes.user_settings_path(conn, :edit))
:error ->
conn
|> put_flash(:error, "Email change link is invalid or it has expired.")
|> redirect(to: Routes.user_settings_path(conn, :edit))
end
end
defp assign_email_and_password_changesets(conn, _opts) do
user = conn.assigns.current_user
conn
|> assign(:email_changeset, Accounts.change_user_email(user))
|> assign(:password_changeset, Accounts.change_user_password(user))
end
end
From my router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {TestAppWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
end
Writing the edit function like this also doesn’t work
def edit(conn, _params, _current_user) do
# IO.inspect layout(conn, :html)
conn
|> put_layout(html: {TestAppWeb.LayoutView, :account})
|> render("edit.html", page_title: "Settings")
end