Hello,
Currently, I am replicating this Blog Post tutorial. I seem to run into a compile error when I attempt to run mix phx.server
It does exist I am not sure how to bypass the error.
This is the code I put into my post_controller.ex
file if i remove it the app runs fine
def show(conn, %{"id" => id}) do
post =
id
|> Posts.get_post!
|> Repo.preload([:comments])
changeset = Comment.changeset(%Comment{}, %{})
render(conn, "show.html", post: post, changeset: changeset)
end
def add_comment(conn, %{"comment" => comment_params, "post_id" => post_id}) do
post =
post_id
|> Posts.get_post!()
|> Repo.preload([:comments])
case Posts.add_comment(post_id, comment_params) do
{:ok, _comment} ->
conn
|> put_flash(:info, "Added comment!")
|> redirect(to: Routes.post_path(conn, :show, post))
{:error, _error} ->
conn
|> put_flash(:error, "Oops! Couldn't add comment!")
|> redirect(to: Routes.post_path(conn, :show, post))
end
end
Here is the compile error that I am receiving when I start the server
== Compilation error in file lib/blog_app_web/controllers/post_controller.ex == ** (CompileError) lib/blog_app_web/controllers/post_controller.ex:71: Comment.__struct__/1 is undefined, cannot expand struct Comment. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
I push the file to a GitHub repo