Hi, I am new to Elixir/Phoenix. This combination seems like an amazing tool though!
I am following: https://dennisbeatty.com/how-to-create-a-todo-list-with-phoenix-liveview.html
to create a simple todo list. Everything works as intended. I want to add a delete button to the list.
Here is what I have done:
<button phx-click="delete" phx-value-id="<%= todo.id %>">Delete</button>
_________________________________________________________________________
def handle_event("delete", %{"id" => id}, socket) do
todo = Todos.get_todo!(id)
Todos.delete_todo(id)
{:noreply, socket}
end
I am getting an error when clicking the button: (FunctionClauseError) no function clause matching in LiveViewTodos.Todos.delete_todo/1
Also, there is a built-in function to handle the delete_todo in my todos.ex:
@doc """
Deletes a todo.
## Examples
iex> delete_todo(todo)
{:ok, %Todo{}}
iex> delete_todo(todo)
{:error, %Ecto.Changeset{}}
"""
def delete_todo(%Todo{} = todo) do
todo
|> Repo.delete()
|> broadcast_change([:todo, :deleted])
end
Can’t seem to figure out what’s going on here. Any help is much appreciated!