PeterDavidCarter

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

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

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

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

NobbZ

Probably routes.jelper not imported.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement