Debugging assigns

jrowah

jrowah

Created 5 months ago

How I quickly debug assigns inside heex templates

 <pre><%= inspect assigns, pretty: true %></pre>

This prints the assigns in a structured manner that is easy to visualise with the pretty assigned to true, ending up with something like:



%{
  socket: #Phoenix.LiveView.Socket<
    id: "phx-GBsoIaUcSHDIE-sH",
    endpoint: MyAppWeb.Endpoint,
    view: MyAppWeb.DashboardLive.Index,
    parent_pid: nil,
    root_pid: #PID<0.12156.0>,
    router: MyAppWeb.Router,
    assigns: #Phoenix.LiveView.Socket.AssignsNotInSocket<>,
    transport_pid: #PID<0.12148.0>,
    ...
  >,
  __changed__: %{page_title: true, current_user: true},
  page_title: "Dashboard",
  current_user: #MyApp.Accounts.User<
    __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
    id: "cdeac003-8bcc-48ef-b1c8-4f3bc75ccbd4",
    email: "test@test.com",
    confirmed_at: ~U[2025-01-14 08:52:24Z],
    inserted_at: ~U[2025-01-14 08:51:41Z],
    updated_at: ~U[2025-01-14 08:52:24Z],
    ...
  >,
  flash: %{},
  live_action: :index
}