Listing Cats
Name | Color | Owner | Category |
---|---|---|---|
Marley | Black | Brian | Real |
MJ | Tortoiseshell | Brian | Real |
Mr. Business | Gray | Gayle | Fictional |
Garfield | Orange | Jon | Fictional |
Goose | Orange | Wendy | Fictional |
NOTE: reference the Setup section for generating the Animals context and adding the Cats to the database used in this example.
scope "/", LiveViewBasicsWeb do
pipe_through :browser
live "/cats", CatLive.Index, :index
end
defmodule LiveViewBasicsWeb.CatLive.Index do
use LiveViewBasicsWeb, :live_view
alias LiveViewBasics.Animals
def mount(_params, _session, socket) do
socket = assign(socket, :cats, Animals.list_cats())
{:ok, socket}
end
def render(assigns) do
~H"""
<Layouts.app flash={@flash}>
<.header>
Listing Cats
</.header>
<div class="mb-2">
<.table id="cats" rows={@cats}>
<:col :let={cat} label="Name">{cat.name}</:col>
<:col :let={cat} label="Color">{cat.color}</:col>
<:col :let={cat} label="Owner">{cat.owner}</:col>
<:col :let={cat} label="Category">{cat.category}</:col>
</.table>
</div>
</Layouts.app>
"""
end
end