PeterDavidCarter
Phx.gen.json API route undefined after added to router.ex
I’ve run phx.gen.json to create an api to search and retrieve json formatted page content dynamically. After I run the command I see this message:
Add the resource to your :api scope in lib/haaksploits_web/router.ex:
resources "/pagecontent", PageContentController, except: [:new, :edit]
Remember to update your repository by running migrations:
$ mix ecto.migrate
However, after adding to the :api scope:
scope "/", HaaksploitsWeb do
pipe_through :browser
pipe_through :api
resources "/pagecontent", PageContentController, except: [:new, :edit]
I get the error:
== Compilation error in file lib/haaksploits_web/controllers/page_content_controller.ex ==
** (CompileError) lib/haaksploits_web/controllers/page_content_controller.ex:18: undefined function page_content_path/3
(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
After running the ecto.migrate. I also tried like this:
scope :api do
resources "/pagecontent", PageContentController, except: [:new, :edit]
But that didn’t work either.
What’s the correct way to add the json resource to the api scope?
Marked As Solved
NobbZ
That won’t help against module clashes with a globally installed archive. That’s why I said it has to be removed first to it sorted step by step.
Also Liked
PeterDavidCarter
I tried Distillery but a bunch of things broke so I moved more low-tech. Nothing told me to do mix archive.install except I did a Google search on Phoenix Framework and ‘archive’ and that was all of relevance that came up. You seemed to be assuming I would know what you meant about removing an archive and that seemed the only way you would have. At the moment I am between jobs and my main focus is to make the app work and make money, or at least use it as a portfolio. I haven’t had time to look into all the details and I’m kind of “funds limited”. I just follow the tutorials where they seem to suit and assume if I do I’m in safe hands.
I have never done a mix archive.install except where I Google searched what you said and that seemed the only logical conclusion. The guides aren’t even clear on what the archive is, and I certainly didn’t run any commands relative to it prior to the problem, though I’d like to help get it cleared up for future users.
kokolegorille
I think it should be
scope "/api", HaaksploitsWeb do
pipe_through :api
...
end
scope "/", HaaksploitsWeb do
pipe_through :browser # Use the default browser stack
...
end
You might also show page_content_controller.ex because the error is inside.
NobbZ
Probably routes.jelper not imported.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









