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
defmodule HaaksploitsWeb.PageContentController do
use HaaksploitsWeb, :controller
alias Haaksploits.PageData
alias Haaksploits.PageData.PageContent
action_fallback HaaksploitsWeb.FallbackController
def index(conn, _params) do
pagecontent = PageData.list_pagecontent()
render(conn, "index.json", pagecontent: pagecontent)
end
def create(conn, %{"page_content" => page_content_params}) do
with {:ok, %PageContent{} = page_content} <- PageData.create_page_content(page_content_params) do
conn
|> put_status(:created)
|> put_resp_header("location", page_content_path(conn, :show, page_content))
|> render("show.json", page_content: page_content)
end
end
def show(conn, %{"id" => id}) do
page_content = PageData.get_page_content!(id)
render(conn, "show.json", page_content: page_content)
end
def update(conn, %{"id" => id, "page_content" => page_content_params}) do
page_content = PageData.get_page_content!(id)
with {:ok, %PageContent{} = page_content} <- PageData.update_page_content(page_content, page_content_params) do
render(conn, "show.json", page_content: page_content)
end
end
def delete(conn, %{"id" => id}) do
page_content = PageData.get_page_content!(id)
with {:ok, %PageContent{}} <- PageData.delete_page_content(page_content) do
send_resp(conn, :no_content, "")
end
end
end
It was autogenned by the phx client, but I am seeing this error in my IDE next to the HaaksploitsWeb, :controller line:
(CompileError) module HaaksploitsWeb.Router.Helpers is not loaded and could not be found
I’ve seen this error a few times when doing various things with my app and it often seems to go away when I reclone the repo, but not this time.
As far as I remember that module gets created when compiling the router as well. Please do a mix clean and a mix build and show full transcript of the latter.
Oh, I tried pushing everything to my remote repo and recloning but the problem reoccurs. I guess that’s what was meant by archive because I tried mix archive.remove but I don’t think that a thing? I also tried removing the _build directory but that doesn’t work either. I’m going to try recloning the repo in a new user-area to see if I can isolate whether it’s the code or a corruption of some sort in the environment but any further suggestions welcome.
Easiest thing to remove an archive is to remove the corresponding subfolder from ~/.mix/archives.
A good estimate of the exact path can be made from the module redefinition warnings you posted earlier.
Also you usually do not want to install full phoenix applications as an archive. Those are meant for small extensions to mix. Not fully fledged applications.
I’ve removed the archive. What’s the correct way to install for a fully fledged app i.e. how should I install it now to make sure I don’t have similar issues now or in the future? I simply followed the instructions in the Phoenix Framework setup guides and was not aware of the term archive specifically.
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.