I have this simple view in my views
folder, but I’m having compilation errors.
defmodule ZZZWeb.ListingLive.ShowView do
use ZZZWeb, :view
def currency(amount) do
money = Money.new(amount, :USD)
Money.to_string(money)
end
end
In my template:
<h2 class="text-3xl font-bold mb-1">
<%= currency @listing.price %>
</h2>
Finally my LiveView module:
defmodule ZZZWeb.ListingLive.Show do
use ZZZWeb, :live_view
alias ZZZ.Listings
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
end
@impl true
def handle_params(%{"id" => id}, _, socket) do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:listing, Listings.get_listing!(id))}
end
defp page_title(:show), do: "Show Listing"
defp page_title(:edit), do: "Edit Listing"
end
Here’s the compilation error:
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1]
Compiling 1 file (.ex)
== Compilation error in file lib/zzz_web/live/listing_live/show.ex ==
** (CompileError) lib/zzz_web/live/listing_live/show.html.leex:115: undefined function currency/1
(elixir 1.12.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
(stdlib 3.15.1) erl_eval.erl:685: :erl_eval.do_apply/6