Hi All, I am setting up some html routes on a json api server that I’ve
been working and am missing an important step. The error message is
listed first, then the code that I have added that seems relevant.
Error message
UndefinedFunctionError at GET /print/documents/1
function Koko.Web.LayoutView.render/2 is undefined (module Koko.Web.LayoutView is not available)
router.ex
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
scope "/print", Koko.Web do
pipe_through :browser
get "/documents/:id", PrintController, :show
end
print_controller.ex
defmodule Koko.Web.PrintController do
use Koko.Web, :controller
alias Koko.Repo
alias Koko.DocManager.Document
def show(conn, %{"id" => id}) do
document = Repo.get(Document, id)
render conn, "plain.html", document: document
end
end
That means it will do an html render, which since you are using the Phoenix helper it will auto-specify a layout option (which you can set to nil to disable). Since I’m guessing you don’t need the whole layout stuff you can just call Koko.Web.PrintView.render("plain.html", document: document) directly and skip it.
Or you can make a LayoutView and add a (filled or empty) layout.