Erroneous template_not_found error

I’m trying to generate JSON from an API controller, it’s configured the following way:

  pipeline :api do
    plug :accepts, ["json"]

  # Other scopes may use custom stacks.
   scope "/api", ApiWeb do
     pipe_through :api
     resources "/categories", CategoryController, only: [:index]  

defmodule Api.CategoryController do
  use ApiWeb, :controller

  alias Api.Category

  def index(conn, _params) do
    categories = Frobl.Category.get_all()
    render(conn, "index.json", categories: categories)


And the view…
defmodule Api.CategoryView do
use ApiWeb, :view

  def render("index.json", %{categories: categories}) do
    render_many(categories, Api.CategoryView, "category.json")

  def render("category.json", %{ category: category }) do
    %{order: category.order, name:, tag: category.tag }

This always results in:
** (Phoenix.Template.UndefinedError) Could not render “category.json” for ApiWeb.CategoryView, please define a matching clause for render/2 or define a template at"lib/api_web/templates/category". No templates were compiled for this module.

This is quite baffling because I should be matching accordingly, but for some reason it’s not matching on the correct render clause.

Can someone please lend some advice?

I found my error, I had a renamed a different file and it had the same definition which the errors were coming from. I deleted it and fiddled a bit and got it working.

1 Like