Route not Recognized

Hi, entity_tx_path route is not working:

These are my routes

    get "/", PageController, :index
    resources "/person", PersonController, only: [:index, :show, :new, :create]
    resources "/entity", EntityController, only: [:index, :show] do
      resources "/member", MemberController, only: [:index]
      resources "/wealth", WealthController, only: [:index, :show]
      resources "/tx", TxController, only: [:new, :create]

I can see them when: mix phx.routes:

         page_path  GET   /                              Finance.PageController :index
       person_path  GET   /person                        Finance.PersonController :index
       person_path  GET   /person/new                    Finance.PersonController :new
       person_path  GET   /person/:id                    Finance.PersonController :show
       person_path  POST  /person                        Finance.PersonController :create
       entity_path  GET   /entity                        Finance.EntityController :index
       entity_path  GET   /entity/:id                    Finance.EntityController :show
entity_member_path  GET   /entity/:entity_id/member      Finance.MemberController :index
entity_wealth_path  GET   /entity/:entity_id/wealth      Finance.WealthController :index
entity_wealth_path  GET   /entity/:entity_id/wealth/:id  Finance.WealthController :show
    entity_tx_path  GET   /entity/:entity_id/tx/new      Finance.TxController :new
    entity_tx_path  POST  /entity/:entity_id/tx          Finance.TxController :create

However when I place the entity_tx_path in tx index.html.eex:

<%= form_for @conn, entity_tx_path(@conn, :create), [as: "new_tx"], fn f -> %>
  <%= submit "Submit" %>
  <% end %>

I got this error:

== Compilation error in file web/views/tx_view.ex ==
** (CompileError) web/templates/tx/new.html.eex:43: undefined function entity_tx_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:121: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

What could be happening?

Your entity_tx_path route requires an entity to be passed to it. Perhaps you mean: entity_tx_path(@conn, :create, @entity) ?

1 Like

Are you useing your *Web-module with :view option in the View-module?

This is necessary to actually import the path helpers.

Thanks! The entity value fixed the issue :slight_smile: