Could not render "new.html" for RumbleWeb.UserView

I currently make it thru “Programming Phoenix” from pragprog.com. I’m as far that i have a controller (UserController) with the functions index, new and show. Index and show work perfectly fine but for the new function i get the error:

# Could not render "new.html" for RumbleWeb.UserView, please define a matching clause for render/2 or define a template at "lib/rumble_web/templates/user". The following templates were compiled:
* index.html 
* show.html 

The file new.html.eex exists. I have checked my code against the book several times and could not find out why the html template under templates/user/new.html.eex can not be compiled. I tried to remove the code in new.html.eex to a simple string but did not help either.

What does your router and user controller look like?

After a lot of testing i found a solution. I executed ‘mix deps.clean --all’ which forced a recompile and everything worked.

I am going through the same problem but running mix deps.clean --all didn’t solve the problem.

Can you share your controller? We can’t know what is causing this error without seeing the code.

Sure

defmodule RumblWeb.UserController do
  use RumblWeb, :controller
  alias Rumbl.Accounts

  def index(conn, _params) do
    users = Accounts.list_users()
    render(conn, "index.html", users: users)
  end
  def show(conn, %{"id" => id}) do
    user = Accounts.get_user(id)
    render(conn, "show.html", user: user)
  end
  def testing(conn, %{"id" => id}) do
    user = Accounts.get_user(id)
    render(conn, "testing.html", user: user)
  end
end

That is my controller, the view exists. It is rendering index.html.heex but failed to render any other view in the same user templates dir.

When I try running this command, I get this error output on the terminal.

$ mix deps.clean --all
* Cleaning castore
* Cleaning connection
* Cleaning cowboy
* Cleaning cowboy_telemetry
* Cleaning cowlib
* Cleaning db_connection
* Cleaning decimal
* Cleaning ecto
* Cleaning ecto_sql
* Cleaning esbuild
* Cleaning file_system
** (File.Error) could not remove files and directories recursively from "c:/Users/simon/OneDrive/Desktop/programming/phoenix/rumbl/_build/dev/lib/file_system": file already exists
    (elixir 1.14.1) lib/file.ex:1339: File.rm_rf!/1
    (elixir 1.14.1) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
    (mix 1.14.1) lib/mix/tasks/deps.clean.ex:115: anonymous fn/6 in Mix.Tasks.Deps.Clean.do_clean/5
    (elixir 1.14.1) lib/enum.ex:975: Enum."-each/2-lists^foreach/1-0-"/2
    (mix 1.14.1) lib/mix/tasks/deps.clean.ex:66: Mix.Tasks.Deps.Clean.run/1
    (mix 1.14.1) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
    (mix 1.14.1) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I solved that error by removing :gettext from the line below in mix.exs

compilers: [:gettext] ++ Mix.compilers(),

.It was causing the errors. I changed that code to:

compilers: [] ++ Mix.compilers(),

and now it works.

You can remove the whole line if you’re not defining any custom compilers. Mix.compilers() is the default.

I didn’t know that. I am a beginner in Phoenix