Getting undefined function topic_path/2 - expected Discuss.TopicView to define such a function or for it to be imported, but none are available

lib/discuss_web/templates/topic/new.html.eex:1: undefined function topic_path/2 (expected Discuss.TopicView to define such a function or for it to be imported, but none are available)

I am trying to troubleshoot this error topic_path and new.html.eex is expecting a import, tried to search the docs and guide for these keywords and not finding any relevant hits, played around a bit.

new.hml.eex

<%= form_for @changeset, topic_path(@conn, :create), fn f ->%>
    <h4>Hello!</h4>
<% end %>
defmodule Discuss.TopicView do
  use DiscussWeb, :view
end

Try Routes.topic_path(…). Phoenix changed from importing route helpers to aliasing the module quite a while ago. If that doesn’t help you should confirm the route and related helper function exists (mix phx.routes).

2 Likes

the error changed as follows.

<%= form_for @changeset, Routes.topic_path(@conn, :create), fn ->%>
<% end %>
 ** (UndefinedFunctionError) function DiscussWeb.TopicView.render/2 is undefined (module DiscussWeb.TopicView is not available)
        DiscussWeb.TopicView.render("new.html", %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{layout: {DiscussWeb.LayoutView, "app.html"}}, body_params: %{}, cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.546.0>, params: %{}, path_info: ["topics", "new"], path_params: %{}, port: 
4000, private: %{DiscussWeb.Router => {[], %{Plug.Swoosh.MailboxPreview => ["mailbox"]}}, :before_send => [#Function<0.20795500/1 in Plug.CSRFProtection.call/2>, #Function<2.36663997/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.84243074/1 in Plug.Session.before_send/2>, #Function<0.11807388/1 in Plug.Telemetry.call/2>, #Function<1.100171616/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], :phoenix_action => :new, :phoenix_controller => DiscussWeb.TopicController, :phoenix_endpoint => DiscussWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {DiscussWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {DiscussWeb.LayoutView, :root}, :phoenix_router => DiscussWeb.Router, :phoenix_template => "new.html", :phoenix_view => DiscussWeb.TopicView, :plug_session => %{"_csrf_token" => "eH3RT2vFBkNpNZtrVAy7PG-5"}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-ZA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7"}, {"connection", "keep-alive"}, {"cookie", "__gads=ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g; __gpi=UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw; _discuss_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, {"host", "localhost:4000"}, {"sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""}, {"sec-ch-ua-mobile", "?0"}, {"sec-ch-ua-platform", "\"Windows\""}, {"sec-fetch-dest", "document"}, {"sec-fetch-mode", "navigate"}, {"sec-fetch-site", "none"}, {"sec-fetch-user", "?1"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}], request_path: "/topics/new", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "Fxh2yshy1xgjrEsAAAPC"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}})
        (phoenix_view 1.1.2) lib/phoenix/view.ex:298: Phoenix.View.render_within/3
        (phoenix 1.6.12) lib/phoenix/controller.ex:784: Phoenix.Controller.render_with_layouts/5
        (phoenix 1.6.12) lib/phoenix/controller.ex:772: Phoenix.Controller.render_and_send/4
        (discuss 0.1.0) lib/discuss_web/controllers/topic_controller.ex:1: DiscussWeb.TopicController.action/2    
        (discuss 0.1.0) lib/discuss_web/controllers/topic_controller.ex:1: DiscussWeb.TopicController.phoenix_controller_pipeline/2
        (phoenix 1.6.12) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
        (discuss 0.1.0) lib/discuss_web/endpoint.ex:1: DiscussWeb.Endpoint.plug_builder_call/2
        (discuss 0.1.0) lib/plug/debugger.ex:136: DiscussWeb.Endpoint."call (overridable 3)"/2
        (discuss 0.1.0) lib/discuss_web/endpoint.ex:1: DiscussWeb.Endpoint.call/2
        (phoenix 1.6.12) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4       
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
[debug] Live reload: lib/discuss_web/templates/topic/new.html.eex
[debug] Live reload: lib/discuss_web/templates/topic/new.html.eex
Compiling 1 file (.ex)
[info] GET /topics/new
[debug] Processing with DiscussWeb.TopicController.new/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 500 in 106ms
[error] #PID<0.562.0> running DiscussWeb.Endpoint (connection #PID<0.561.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /topics/new
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function DiscussWeb.TopicView.render/2 is undefined (module DiscussWeb.TopicView is not available)       
        DiscussWeb.TopicView.render("new.html", %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{layout: {DiscussWeb.LayoutView, "app.html"}}, body_params: %{}, cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.562.0>, params: %{}, path_info: ["topics", "new"], path_params: %{}, port: 4000, private: %{DiscussWeb.Router => {[], %{Plug.Swoosh.MailboxPreview => ["mailbox"]}}, :before_send => [#Function<0.20795500/1 in Plug.CSRFProtection.call/2>, #Function<2.36663997/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.84243074/1 in Plug.Session.before_send/2>, #Function<0.11807388/1 in Plug.Telemetry.call/2>, #Function<1.100171616/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], :phoenix_action => :new, :phoenix_controller => DiscussWeb.TopicController, :phoenix_endpoint => DiscussWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {DiscussWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {DiscussWeb.LayoutView, :root}, :phoenix_router => DiscussWeb.Router, :phoenix_template => "new.html", :phoenix_view => DiscussWeb.TopicView, :plug_session => %{"_csrf_token" => "eH3RT2vFBkNpNZtrVAy7PG-5"}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-ZA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7"}, {"cache-control", "max-age=0"}, {"connection", "keep-alive"}, {"cookie", "__gads=ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g; __gpi=UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw; _discuss_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, {"host", "localhost:4000"}, {"referer", "http://localhost:4000/topics/new"}, {"sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""}, {"sec-ch-ua-mobile", "?0"}, {"sec-ch-ua-platform", "\"Windows\""}, {"sec-fetch-dest", "document"}, {"sec-fetch-mode", "navigate"}, {"sec-fetch-site", "same-origin"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}], request_path: "/topics/new", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "Fxh3Iv8bxxgktZQAAADh"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}})

So I did some research and found a solution dated 2018, that I implemented. I have a different error now.

Request: GET /topics/new
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function DiscussWeb.TopicView.render/2 is undefined (module DiscussWeb.TopicView is not available)
        DiscussWeb.TopicView.render("new.html", %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #DiscussWeb.Topic<>, valid?: false>, conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{changeset: #Ecto.Changeset<action: nil, changes: %{}, errors: [title: {"can't be blank", [validation: :required]}], data: #DiscussWeb.Topic<>, valid?: false>, layout: {DiscussWeb.LayoutView, "app.html"}}, body_params: %{}, cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.588.0>, params: %{}, path_info: ["topics", "new"], path_params: %{}, port: 4000, private: %{DiscussWeb.Router => {[], %{Plug.Swoosh.MailboxPreview => ["mailbox"]}}, :before_send => [#Function<0.20795500/1 in Plug.CSRFProtection.call/2>, #Function<2.36663997/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.84243074/1 in Plug.Session.before_send/2>, #Function<0.11807388/1 in Plug.Telemetry.call/2>, #Function<1.100171616/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], :phoenix_action => :new, :phoenix_controller => DiscussWeb.TopicController, :phoenix_endpoint => DiscussWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {DiscussWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {DiscussWeb.LayoutView, :root}, :phoenix_router => DiscussWeb.Router, :phoenix_template => "new.html", :phoenix_view => DiscussWeb.TopicView, :plug_session => %{"_csrf_token" => "eH3RT2vFBkNpNZtrVAy7PG-5"}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"__gads" => "ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g", "__gpi" => "UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw", "_discuss_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-ZA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7"}, {"connection", "keep-alive"}, {"cookie", "__gads=ID=bb87c45b4ea925ba-22f91ec9b6d3008e:T=1653065583:RT=1653065583:S=ALNI_MZ-UckDPUlsKS2DJRQ5R-4UyhAk2g; __gpi=UID=0000072ea6d60b8d:T=1653065583:RT=1653323020:S=ALNI_MbHCVMKuGf2sQn8u_vGBrMGWkIyZw; _discuss_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYZUgzUlQydkZCa05wTlp0clZBeTdQRy01.wtEEbADSSVa1c1JOOy3KovyTMxXSMT_upyl4H7GYkzk"}, {"host", "localhost:4000"}, {"sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\""}, {"sec-ch-ua-mobile", "?0"}, {"sec-ch-ua-platform", "\"Windows\""}, {"sec-fetch-dest", "document"}, {"sec-fetch-mode", "navigate"}, {"sec-fetch-site", "none"}, {"sec-fetch-user", "?1"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}], request_path: "/topics/new", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "Fxi8u-YuyJjo--QAAAFD"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, 
{"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}}) 
        (phoenix_view 1.1.2) lib/phoenix/view.ex:298: Phoenix.View.render_within/3        (phoenix 1.6.12) lib/phoenix/controller.ex:784: Phoenix.Controller.render_with_layouts/5
        (phoenix 1.6.12) lib/phoenix/controller.ex:772: Phoenix.Controller.render_and_send/4
        (discuss 0.1.0) lib/discuss_web/controllers/topic_controller.ex:1: DiscussWeb.TopicController.action/2
        (discuss 0.1.0) lib/discuss_web/controllers/topic_controller.ex:1: DiscussWeb.TopicController.phoenix_controller_pipeline/2
        (phoenix 1.6.12) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2     
        (discuss 0.1.0) lib/discuss_web/endpoint.ex:1: DiscussWeb.Endpoint.plug_builder_call/2
        (discuss 0.1.0) lib/plug/debugger.ex:136: DiscussWeb.Endpoint."call (overridable 3)"/2
        (discuss 0.1.0) lib/discuss_web/endpoint.ex:1: DiscussWeb.Endpoint.call/2 
        (phoenix 1.6.12) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.9.0) g:/docs/github/elixir/discuss/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

This file was changed to a .heex file to update the code no effect.

<%= form_for @changeset, Routes.topic_path(@conn, :create), fn f ->%>
<div class="form-group">
    <%= text_input f, :title, placeholder: "Title", class: "form-control" %>
</div>
<%= submit "Save Topic", class: "btn btn-primary"%>
<% end %>

This is the key part of the error message…

This is the reason why…

I also thought the same thing and changed that code using search and replace.

defmodule Discuss.TopicView do
  use Discuss, :view
end

The error then changed to, Is there a different suggestion of getting the module available?

== Compilation error in file lib/discuss/topic.ex ==
** (CompileError) lib/discuss/topic.ex:4: undefined function schema/2 (there is no such import)

Is this progress?

Yes it is a progress… but each time You have an error, it refers to a file. You should show this file, as we have no clue about what code produces the error.

I am not sure You have corrected the previous error correctly.

You should have

defmodule DiscussWeb.TopicView do
  use Discuss, :view
end

In Elixir, errors are first class citizen. Not understanding an error is subject to PR, to increase error readabiility.

1 Like

this file topic_view is still like this unchanged.

The topic.ex file was untouched and was working before.

This is the topic.ex file

defmodule DiscussWeb.Topic do
  use DiscussWeb, :model

  schema "topics" do
    field(:title, :string)
  end

  def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:title])
    |> validate_required([:title])
  end
end

A lot of attempts thus far has been attempted. The current version of the error is different from before. I am working on trying to solve it, in an attempt to move back to the original error. This is the new version of the error since the code has changed.

== Compilation error in file lib/discuss_web/controllers/topic_controller.ex ==
** (CompileError) lib/discuss_web/controllers/topic_controller.ex:1: undefined function put_new_layout/2 (expected DiscussWeb.TopicController to define such a function or for it to be imported, but none are available)

This is the original error.

Althought Elixir is very flexible in naming convention, You should follow some convention if You use Phoenix.

That is wrong, a view belongs to the web part.

That is wrong, schema don’t belong to web part.

I don’t know which tuto You follow, but You have multiple naming’s errors.

i see. The course is a bit old, was recommended that I just read up how to modernise the code related to the updates. hopefully the course will be taken down in time. I am aware of this naming convention issue. I have tried a search and replace method. Based on the new errors I reverted the change. The docs imo do not fully illustrate in examples on how to deal with context files.

1 Like

The doc might use an old Phoenix version.

Using eex templates is already an indication, because new templates use heex.

Not using Routes before path halpers suggest Phoenix 1.2, maybe 1.3

When You create a project…

mix phx new discuss

You will have lib/discuss and lib/discuss_web

Everything in discuss should be prefixed with Discuss, while everything in discuss_web should stsrt with DiscussWeb.

I strongly discourage using old tuto because newer Phoenix (1.6 and soon to be 1.7) have changed a lot.

I also encourage You to try generators, as it might help You in the beginning.

mix phx.gen.json
mix phx.gen.html
mix phx.gen.live
1 Like

After using Routes.topic_path() i have fix Getting undefined function topic_path/2 this error but got another error which is,

function DiscussWeb.DiscussWeb.TopicController.init/1 is undefined (module DiscussWeb.DiscussWeb.TopicController is not available)

in my router.ex

scope “/”, DiscussWeb do
pipe_through :browser
get “/”, PageController, :index
get “/topics/new”, TopicController, :new
post “/topics”, TopicController, :create

end

and in my Topic_controller.ex

defmodule DiscussWeb.TopicController do
use DiscussWeb, :controller
alias DiscussWeb.Topic
def new(conn, params) do
changeset = Topic.changeset(%Topic{}, %{})
render(conn, “new.html”, changeset: changeset)
end
end

can you please help me out here
also @kokolegorille do you have any idea for this?

You can check your routes with

mix routes

and…

It’s a mistake in the controller’s name…

When You create a project, let’s call it App, then there will be App and AppWeb

But because You called your project DiscussWeb, there should be DiscussWeb and DiscussWebWeb, which is a little bit confusing.

I do not recommend to call your project with web inside the name :slight_smile: