Assign not available in new Phoenix 1.5.8

Hello, I am tryin to implement my “players” (phoenix resource) in “gladiators” (resource). I think everything is right, but I still get the error that " assign @players not available in eex template." (the template is .leex).
To mention - My Phoenix version is 1.5.8, I do the same in an another project and everything is just fine…

My gladiator live is:

defmodule TennisWeb.GladiatorLive do
  use TennisWeb, :live_view

  alias TennisWeb.GladiatorView
  alias Tennis.Players
  alias Tennis.Accounts
  alias Tennis.Tours


  def render(assigns) do
   render GladiatorView, "show.html", assigns
  end

  @impl true
  def mount(params, %{"admin_token" => admin_token} = _session, socket) do
    gladiator = Tours.get_gladiator!(params["id"])
    players = Players.list_players
    admin = Accounts.get_admin_by_session_token(admin_token)
    socket = assign(
        socket,
        gladiator: gladiator,
        players: players,
        current_admin: admin
      )
    {:ok, socket}
  end

end

The Routes are

    resources "/gladiators", GladiatorController
    resources "/players", PlayerController
    live "/gladiator_live/:id", GladiatorLive

The gladiator :show:

# show,html.leex
<tbody>
  <%= for player <- @players do %>
  <tr>
  <td class="px-4 py-3"> <%= player.name %> </td>
  <tr>
(...)

I’m in dead end, thoughts?

Rename show.html.leex to gladiator_live.html.leex and make sure it’s in the same directory as the module. Then you can remove the render/1 function entirely.

Did you mean to call Players.list_players()? Just checking.

Tested it, not working :slight_smile: I think that in the new Phoenix 1.5.8 something is different, coz this code is fine in 1.5.7, not found anything useful in the net…

Thanks for the opinion, but it this way my resource breaks

I just looked at the diff in phoenix sources from 1.5.7 to 1.5.8

No big changes, must be something else :thinking:

From examples here Phoenix.LiveView — Phoenix LiveView v0.15.4 you render template with another name like this Phoenix.View.render(MyAppWeb.PageView, "page.html", assigns). Are you sure your render is Phoenix.View.render?

1 Like

SOLVED: Apparently the issue is all about router.ex.

shoud be live "/gladiators/:id", GladiatorLive

and here I remove the show render:
resources "/gladiators", GladiatorController, except: [:show]

Yeah, that is good to know, Thanks :slight_smile:

1 Like