Undefined function session_path/2


I am having trouble debugging an error:

== Compilation error in file lib/booking_central_web/views/session_view.ex ==
** (CompileError) lib/booking_central_web/templates/session/register.html.eex:9: undefined function session_path/2
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

Here is my router:

    scope "/", BookingCentralWeb do
    pipe_through :browser # Use the default browser stack

    get "/", DashboardController, :index
    get "/login", SessionController, :login_form
    get "/register", SessionController, :register_form
    post "/register", SessionController, :register_user

I have a controller:

defmodule BookingCentralWeb.SessionController do
  use BookingCentralWeb, :controller

  alias BookingCentral.Accounts.{Registration}

  plug :put_layout, "accounts.html"

    def login_form(conn, _params) do
        render conn, "login.html"

    def register_form(conn, _params) do
        changeset = Registration.changeset(%Registration{})
        render conn, "register.html", changeset: changeset

    def register_user(conn, %{"registration_params" => params}) do
        IO.inspect params
        render conn, "login.html"


Here is my View:

defmodule BookingCentralWeb.SessionView do
  use BookingCentralWeb, :view

And I am referencing the session_path in my form:

<%= form_for @changeset, session_path(@conn, :register_user), fn f -> %>

Any suggestions for working out why I get this error are appreciated.



The error says there is no session_path, which is the case…

Which line in your router makes You think it is?

You might confirm with

$ mix phx.routes

Are you using Phoenix 1.4 by chance? You need to use Routes.session_path() if you are.

get "/login", SessionController, :login_form
get "/register", SessionController, :register_form
post "/register", SessionController, :register_user

All three of those should define session_path in 1.3

1 Like

Thanks … this is it!

1 Like

That is a bit embarassing :slight_smile:

Sorry for misleading answer

All good. I had seen this change … but forgot all about it!

Thank you so much, I did not know that. Could tell me what it has changed?

There is a new alias Routes for all of the generated paths