Hello!.
I am trying to add Nested Resources in router.ex like this…
resources "/phonebooks", PhonebookController do
resources "/people", PersonController, except: [:index]
end
and added, templates(using phonebook_person_path() ) and controller
and then I did mix phx.routes to see, but it doesn’t compile. it says,
== Compilation error in file lib/mmarketing_web/views/dashboard/person_view.ex ==
** (CompileError) lib/mmarketing_web/templates/dashboard/person/new.html.eex:3: undefined function phonebook_person_path/2
Please tell me what I am missing
Thank you!
NobbZ
May 4, 2018, 9:11pm
2
What’s the output of mix phx.routes
?
1 Like
I haven’t used nested resources but could it be that in your template you are not passing enough arguments to phonebook_person_path()
If you look here…
https://hexdocs.pm/phoenix/routing.html#nested-resources
They have this example …
iex> HelloWeb.Router.Helpers.user_post_path(Endpoint, :show, 42, 17)
You could try to do something similar from iex to try to debug the problem.
NobbZ
May 5, 2018, 7:18am
4
I think the best were just to look at the output of mix phx.routes
as we have complicated pluralisation in this example. We should take a look at what phoenix tries to do from it.
NobbZ
May 5, 2018, 9:29am
5
I checked on my own (just added the provided snippet in a routes file of mine) and pluralisation seems to work fine.
Then I took a closer look at the error message and have seen, that it is called with only 2 arguments, but it needs 4.
the conn or endpoint
the action
the phonebook_id
the id
2 Likes
Thanks! it compiles!
I i didn’t know I had to pass 2 more arguments including conn, and action.
1 Like