Undefined view, but it exists - Phoenix

Hello.

I’m trying to have 2 different scopes, one "/" and the other one "/admin". Admin scope uses MovieTheater.Admin, so I have created a MovieTheather.MovieController and a MovieTheater.Admin.MovieController. my admin scope also has to be as: :admin to prevent errors with my "/" scope, that way I can use admin_movie_path and also, should be able to use movie_path but it doesn’t work.

It just says

function MovieTheater.MovieView.render/2 is undefined (module MovieTheater.MovieView is not available)

But I have created the view:

defmodule MovieTheater.MovieView do
  use MovieTheater.Web, :view
end

These are my routes

scope "/admin", MovieTheater.Admin, as: :admin do
  pipe_through [:browser, :browser_session, :auth, :current_user]
    
  get "/dashboard", PageController, :dashboard
  resources "/movies", MovieController
end

scope "/", MovieTheater do
  pipe_through [:browser, :current_user]

  get "/", PageController, :index
  resources "/users", UserController, only: [:new, :create]
  resources "/sessions", SessionController, only: [:new, :create, :delete]
  resources "/movies", MovieController, only: [:index, :show]
end

What could be wrong?

Thanks for your help.

First things first, let’s make sure your view module really does exist. Can you run the following and include the following output?

  1. $ ls -R web/views
  2. $ ls -R _build/dev | grep MovieTheater.MovieView
  3. iex -S mix, then iex> Code.ensure_loaded(MovieTheater.MovieView)

Obvious things to check for. Did you save the file as .ex, not .exs?

3 Likes

Seems like it didn’t compile, I ran

$ ls -R web/views:

web/views:
admin/ error_helpers.ex error_view.ex layout_view.ex movie_view.ex page_view.ex session_view.ex user_view.ex

web/views/admin:
admin_movie_view.ex admin_page_view.ex

But $ ls -R _build/dev | grep MovieTheater.MovieView didn’t return anything, so I deleted my builds, compiled again and now it’s working, thanks @chrismccord

1 Like