Elixir/phoenix error - comprehensions must start with a generator

web/templates/topic/index2.html.eex:3: for comprehensions must start with a generator.

Please I new to elixir and I gets above error shows up when I try to execute phoenix server.
How can I fixed it. thanks in advance.

Hello, welcome to the forum.

The error message means You have a wrong syntax in the for comprehension command used in index2 template. Probably something like

<%= for x <- generator do %>
  ...
<% end %>

But for us to help You, You will need at least to provide the failing template. (And maybe your controller code)

Please show the code You have in index2…

2 Likes

Thank you very much @kokolegorille, I apologize for the incomplete information, please find below my template code:

    <%= for topic in topics do %>
  • <%= topic.title %>
  • <% end %>

I don’t know the rest of your code, but I assume topics is setup in the controller, and passed to the template…

In that case, You should use @topics instead of topics in the template.

3 Likes

Thank you very much your suggestion solved the problem,
However, I changed in to <- as well for it work

1 Like

Glad You solved it.

1 Like