calling: http://localhost:4000/m/7xfksimqi4dzrwmv I get the error:
Phoenix.Template.UndefinedError at GET /m/7xfksimqi4dzrwmv
Could not render "root.json" for FaithfulWordWeb.LayoutView, please define a matching clause for render/2 or define a template at "lib/faithful_word_web/templates/layout/*". The following templates were compiled:
* _layout.html
* _layout.text
* _user_menu.html
* app.html
* email.html
* email.text
* live.html
* root.html
* session.html
my code:
def show(conn, %{"readable_id" => readable_id}) do
result = MediaItemApi.media_item_by_readable_id(readable_id)
IO.inspect(result, label: "media_item_by_readable_id result")
result
|> case do
{:error, nil} ->
put_status(conn, 404)
|> put_view(ErrorView)
|> render("404.json", %{message: "error showing media item."})
{:ok, media_item} ->
render(conn, "show.html", media_item: media_item)
end
I’m not sure why it doesn’t just render a 404? I just don’t get why phoenix is asking for a “root.json” template. The site is LiveView-centric, I’m just trying to render a 404 when the user doesn’t enter a correct readable_id
on a mediaitem. Works fine when the correct readable_id is passed. I have this in my router:
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {FaithfulWordWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug FaithfulWordWeb.GenerateCSRF
plug FaithfulWordWeb.AssignSession
plug :fetch_current_user
end
and the route:
scope "/", FaithfulWordWeb do
pipe_through :browser
live "/", PageLive, :index
get "/faq", FaqController, :new
get "/m/:readable_id", ShareMediaItemController, :show
end
I know it has something to do with plug :put_root_layout, {FaithfulWordWeb.LayoutView, :root}
…