Hello,
I can’t understand why I get this error: no function clause matching in TennisPhxWeb.TourLive.handle_event/3 (tennis_phx 0.1.0) lib/tennis_phx_web/live/tour_live.ex:31: TennisPhxWeb.TourLive.handle_event("add_points", %{"player_points" => %{"points" => "2"}},
.
My heex template:
<%= for player <- @players do %>
<li>
<strong><%= player.name %></strong>
</li>
<form action="#" phx-submit="add_points" phx-value-player-id: "player.id">
<%= number_input :player_points, :points, placeholder: "Something" %>
<%= submit "Add", phx_disable_with: "Adding...." %>
</form>
<% end %>
WHAT IS MY GOAL: In a schema, where I have player_id
from player.id I want to record some points.
def change do
create table(:player_tour) do
add(:player_id, references(:players, on_delete: :delete_all))
add(:tour_id, references(:tours, on_delete: :delete_all))
add(:points, :decimal)
timestamps()
end
For this purpose I need player.id via phx-value-player-id:player.id
in my form. The handle event, where the error is all about:
def handle_event("add_points", %{"player_points" => points_for_player, "player-id" => player_id}, socket) do
tour = socket.assigns[:tour]
|> Repo.preload(:players)
Events.bump_player_points(tour, player_id, points_for_player)
{:noreply, socket}
end
No function clause matching in handle_event/3… I think the error is that I use 4 arguments, although player_points
and player-id
are both unsigned params - here. From this I understand that my cause can be done, can’t it?
Any thoughts?