Phoenix 1.4: module Helpers is not available

Hello, I’m going to create a form in phoenix 1.4, but I have a Helpers error.

my form in my template:

<%= form_for @changeset, admin_dashbord_path(@conn, :cards_category_edit), fn f -> %>

when I use that code I will have this error:

lib/wedding_card_web/templates/admin_dashbord/card-category-edit.html.eex:20: undefined function admin_dashbord_path/2

if I add a Helpers. to admin_dashbord_path, I will have this error:

    ** (UndefinedFunctionError) function Helpers.admin_dashbord_path/2 is undefined (module Helpers is not available)

how can I fix this ?

my router:

  scope "/card-admin", WeddingCardWeb do
    pipe_through :browser

    get "/", AdminDashbordController, :index

    get "/card/category/edit-load", AdminDashbordController, :cards_category_edit_load
    post "/card/category/edit", AdminDashbordController, :cards_category_edit
  end

my Controller:

defmodule WeddingCardWeb.AdminDashbordController do
  use WeddingCardWeb, :controller
  alias WeddingCard.DB.CardCategoryQuery
  def index(conn, _params) do
    render(conn, "index.html")
  end



  # card functions
  def cards_category_edit_load(conn, %{"id" => id}) do
    changeset = CardCategoryQuery.get_category_by_id(id).description
    render(conn, "card-category-edit.html", changeset: changeset)
  end

  def cards_category_edit(conn, _params) do
    render(conn, "card-category-edit.html")
  end

end

You should use Routes.admin_dashbord_path(@conn, :cards_category_edit). Btw, is that a typo in dashboard?

1 Like

I’m afraid I couldn’t know what your question was ?

I think it was fixed , but why didn’t I need this in phoenix 1.3 ? it was changed ?

I’m afraid it was changed.

In 1.3 YouAppWeb.Router.Helpers was imported into view, so you can use admin_dashbord_path, but it’s aliased as Routes now in Phoenix 1.4:

alias YouAppWeb.Router.Helpers, as: Routes

That’s why you need Routes..

2 Likes