Error in template: in form_for phoenix don't see _path function

I observe some strange behavior of form_for helper in my template. Could somebody help me?

== Compilation error in file lib/webtestapp_web/views/payment_view.ex ==
** (CompileError) lib/webtestapp_web/templates/payment/index.html.eex:1: undefined function payment_path/2

#mix phx.routes
page_path  GET   /              WebtestappWeb.PageController :index
payment_path  GET   /payments/new  WebtestappWeb.PaymentController :new
payment_path  POST  /payments      WebtestappWeb.PaymentController :create

# index.html.eex
<%= form_for @conn, payment_path(@conn, :create), [as: :params], fn f -> %>

# router.ex
resources "/payments", PaymentController, only: [:new, :create]

defmodule WebtestappWeb.PaymentController do
  use WebtestappWeb, :controller

  def new(conn, _params) do
    render(conn, "index.html", conn: conn)

# payment_view.ex
defmodule WebtestappWeb.PaymentView do
  use WebtestappWeb, :view

Is that Phoenix 1.4? If so You need to prepend Routes before the path.

Yes, It’s Phoenix 1.4. Could you be more specific, please - where should I prepend routes?

Replace with…

<%= form_for @conn, Routes.payment_path(@conn, :create), [as: :params], fn f -> %>

You can see upgrade guide here


Thank you very much! I spent whole day trying to understand, what’s wrong. Thank you! :grinning:

Your response helped save me a lot of time troubleshooting my simple CRUD app. Thanks!