schema "items" do
field :code, :string
field :name, :string
field :sell_price, :decimal
timestamps()
end
I wanted to have a virtual field, where it will format my sell_price field as string. I recall, in Ecto, you can do this:
field :formatted_sell_price, :string, virtual: true
My question is, how to make Ecto always compute that field to the format that I want? Suppose I already have my own formatting code with Money or Number.
I would like to use it in my .eex file. What’s the best way to do this? So that I can simply use something like <%= item.format_price %> and that’s it.
If I use a function there, I find that I have to call something like: