I practice nested resources, but I got problem in “create” controller.ex. the problem is
Compilation error in file lib/lat5_web/controllers/thread_controller.ex ==
** (CompileError) lib/lat5_web/controllers/thread_controller.ex:32: undefined function category_thread_path/4
(elixir) src/elixir_locals.erl:107: :elixir_locals."-ensure_no_undefined_local/3-lc$^0/1-0-"/2
(elixir) src/elixir_locals.erl:107: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
defmodule Lat5Web.ThreadController do
use Lat5Web, :controller
alias Lat5.Forums
alias Lat5.Forums.Thread
def index(conn, _params, category) do
# we pass it to the `list_threads` function
threads = Forums.list_threads(category)
# and we pass it in our call to render, so templates can refer to it as
# @category.
render(conn, "index.html", threads: threads, category: category)
end
def new(conn, _params, category) do
changeset =
%Thread{category_id: category.id}
|> Forums.change_thread
render(conn, "new.html", changeset: changeset, category: category)
end
def create(conn, %{"thread" => thread_params}, category) do
thread_params =
thread_params
|> Map.put("category_id", category.id)
case Forums.create_thread(thread_params) do
{:ok, thread} ->
conn
|> put_flash(:info, "Thread created successfully.")
|> redirect(to: category_thread_path(conn, :show, category, thread))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset, category: category)
end
end
def show(conn, %{"id" => id}, category) do
thread = Forums.get_thread!(category, id)
render(conn, "show.html", thread: thread, category: category)
end
def edit(conn, %{"id" => id}, category) do
thread = Forums.get_thread!(category, id)
changeset = Forums.change_thread(thread)
render(conn, "edit.html", thread: thread, changeset: changeset, category: category)
end
def update(conn, %{"id" => id, "thread" => thread_params}, category) do
thread = Forums.get_thread!(category, id)
case Forums.update_thread(thread, thread_params) do
{:ok, thread} ->
conn
|> put_flash(:info, "Thread updated successfully.")
|> redirect(to: category_thread_path(conn, :show, category, thread))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", thread: thread, changeset: changeset, category: category)
end
end
def delete(conn, %{"id" => id}, category) do
thread = Forums.get_thread!(category, id)
{:ok, _thread} = Forums.delete_thread(thread)
conn
|> put_flash(:info, "Thread deleted successfully.")
|> redirect(to: category_thread_path(conn, :index, category))
end
def action(conn, _) do
category = Forums.get_category!(conn.params["category_id"])
args = [conn, conn.params, category]
apply(__MODULE__, action_name(conn), args)
end
end