lyo5ha
1
I observe some strange behavior of form_for
helper in my template. Could somebody help me?
#error:
== 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]
...
#payment_controller.ex
defmodule WebtestappWeb.PaymentController do
use WebtestappWeb, :controller
def new(conn, _params) do
render(conn, "index.html", conn: conn)
end
...
# payment_view.ex
defmodule WebtestappWeb.PaymentView do
use WebtestappWeb, :view
end
Is that Phoenix 1.4? If so You need to prepend Routes before the path.
lyo5ha
3
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
2 Likes
lyo5ha
5
Thank you very much! I spent whole day trying to understand, what’s wrong. Thank you!
_n_x
6
Your response helped save me a lot of time troubleshooting my simple CRUD app. Thanks!