I have an endpoint defined in my routes.ex file like this:
scope "/api", TesteWeb do
pipe_through :api
post "/classify", ClassifierController, :classify
end
In my classifier_controller.ex file I have:
defmodule TesteWeb.ClassifierController do
use TesteWeb, :controller
def classify(conn, _params) do
# I'm testing with hardcoded data...
request = %{sentence: "Bom dia", model_id: "123"}
render(conn, "show.json", request: request)
end
end
And finally, in my classifier_view.ex file, I have:
defmodule TesteWeb.ClassifierView do
use TesteWeb, :view
def render("show.json", %{request: request}) do
%{response: render_one(request,TesteWeb.ClassifierView, "response.json")}
end
def render("response.json", %{request: request}) do
%{response: "ok", sentece: request.sentence}
end
end
When I make a POST request to http://localhost:4000/api/classify, I get the following error:
[error] #PID<0.471.0> running TesteWeb.Endpoint (connection #PID<0.470.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api/classify
** (exit) an exception was raised:
** (Phoenix.Template.UndefinedError) Could not render “response.json” for TesteWeb.ClassifierView, please define a matching clause for render/2 or define a template at “lib/teste_web/templates/classifier/*”. No templates were compiled for this module.
Why it can’t render response.json if it is defined in classifier_view.ex?