UndefinedFunctionError at GET /topics/new function Routes.topic_path/2 is undefined (module Routes is not available)

Hello everyone. I’m currently following an Elixir course, and I’ve run into an error stating that the Routes module is undefined. The course I’m following is quite outdated as it was published in 2016. I’ve spent an hour searching for solutions, but I’m still clueless about how to troubleshoot this problem.

new.html.eex

<%= Form.form_for @changeset, Routes.topic_path(@conn, :create), fn f -> %>
  <%= Form.text_input(f, :topic_title) %>
  <%= Form.submit "Save Topic" %>
<% end %>

This is the error I’ve encountered

UndefinedFunctionError at GET/topics/new

function Routes.topic_path/2 is undefined (module Routes is not available)

Hello and welcome.

Recently Phoenix has moved from Routes helpers to verified routes…

You might also have issues converting old code to the new version.

Thank you for your reply. I find it hard to understand what does it means by that. Can you help me troubleshoot my problem? I’ve followed the official documentation of Phoenix.HTML in section forms and followed this format.

<%= form_for @changeset, Routes.user_path(@conn, :create), fn f -> %>
  Name: <%= text_input f, :name %>
<% end %>

and now, I’ve received this error if I remove the Routes

error: undefined function topic_path/2 (expected DiscussWeb.TopicHTML to define such a function or for it to be imported, but none are available)
lib/discuss_web/controllers/topic_html/new.html.heex:2

If I put it back

UndefinedFunctionError at GET /topics/new

function Routes.topic_path/2 is undefined (module Routes is not available)

The best way is to create a new Phoenix project, generate a resource, and see what is generated…

mix phx.new koko
cd koko
mix ecto.create
mix phx.gen.live Accounts User users name:string age:integer

Then look at the generated code for the User resource.

It will look like this

~p"/topics"

I had the same problem i removed Routes.topic_path and used action={~p"/topics"} verified route