Could not render “cardById.json” for RealtimeWeb.CardView, please define a matching clause for render/2 or define a template at “lib/realtime_web/templates/card”. No templates were compiled for this module. Assigns: %{phx_template_not_found:
What is wrong with the way I am calling the cardById.json render function?
render_one/3 expects cards to be a single entity and will accordingly pass cards via the assigns as %{card: cards}. Your "cardById.json" render function requires that the assigns contain :cards (plural). Use render(CardView, "cardById.json", cards: cards) instead.
Alternatively, using your original function:
def render("cardsHash.json", %{cards: cards}) do
%{
"entities": %{
"cards": Map.new(cards, &{&1.id, card_object(&1)})
}
}
end
defp card_object(card) do
%{id: card.id, created_at: card.inserted_at, ...}
end