andrewb

andrewb

Undefined function session_path/2

Hi,

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
    end

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"
    end

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

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

end

Here is my View:

defmodule BookingCentralWeb.SessionView do
  use BookingCentralWeb, :view
end

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.

Andrew

Marked As Solved

sanswork

sanswork

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

Also Liked

sanswork

sanswork

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

andrewb

andrewb

Thanks … this is it!

Last Post!

andrewb

andrewb

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

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement