ykostov
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?
Most Liked
wanton7
From examples here Phoenix.LiveView — Phoenix LiveView v1.2.5 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?
ykostov
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 ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









