Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in a Phoenix template list

I'm trying to extract values form a list (<%= @evento %>) in a template but I'm getting this error:

lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: %Skeleton.News.Evento{__meta__: #Ecto.Schema.Metadata<:loaded, "news_eventos">, date: "DEZ 2011", id: 69, imgPaths: ["images/fabasa/eventos/one/1.jpg", "images/fabasa/eventos/one/2.jpg", "images/fabasa/eventos/one/3.jpg", "images/fabasa/eventos/one/10.jpg"], inserted_at: ~N[2017-06-30 12:38:15.452214],...  

So, my question is how to transform this in a datatype structure that I can still iterate in my template?

like image 808
Paulo Janeiro Avatar asked Jun 30 '17 20:06

Paulo Janeiro


Video Answer


1 Answers

You cannot print a list like that in a template because templates only allow iolists to be printed, which are lists containing integers, binaries (also called String in Elixir), or iolists.

If you want to print the inspect representation of the list (the one you see in iex), you can do:

<%= inspect @evento %>

To iterate through the list, you can use for:

<%= for event <- @evento %>
  <%= event.id %>
<% end %>
like image 173
Dogbert Avatar answered Sep 19 '22 23:09

Dogbert