Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phoenix view module not available

My application works and api json requests and for regular html. My router.ex

defmodule MyApp.Router do
  use MyApp.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/api", MyApp do
    pipe_through :api # Use the default browser stack

    scope "/v1", V1, as: :v1 do
      resources "/users", UserController, except: [:new, :edit, :index]
    end
  end

  scope "/", MyApp do
    pipe_through :browser # Use the default browser stack
    get "/confirm/:token",          UserController, :confirm, as: :user_confirm
  end

end

my web/controllers/v1/user_controller.ex

defmodule MyApp.V1.UserController do
  use MyApp.Web, :controller

  def create(conn, %{"user" => user_params}) do
   ...
          conn
          |> put_status(:created)
          |> put_resp_header("location", v1_user_path(conn, :show, user))
          |> render("sign_up.json", user: Map.put(user, :session, result[:session]))
   ...
  end

and my web/controllers/user_controller.rb

defmodule MyApp.UserController do
  use MyApp.Web, :controller

  alias MyApp.User

  def confirm(conn, %{"token" => token}) do
...
            render(conn, "confirmed.html")
...
  end

end

my web/views/v1/user_view.ex

defmodule MyApp.V1.UserView do
  use MyApp.Web, :view
...
end

and my web/views/user_view.ex

defmodule MyApp.UserView do
  use MyApp.Web, :view

end

Everything works fine until I added a route and a controller for html. Now, when I make a request for api json, I get an error

Request: POST /api/v1/users
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function MyApp.V1.UserView.render/2 is undefined (module MyApp.V1.UserView is not available)

But if I delete web/vews/user_view.ex, then this query works without errors. How can you correct this error?

like image 967
Marsel.V Avatar asked Apr 16 '17 20:04

Marsel.V


1 Answers

These types of errors can usually be resolved by running mix clean. You may also see this type of error during Live code reload in dev. It case, try restarting the Phoenix.Server, and if that does not help, run mix clean

like image 106
Steve Pallen Avatar answered Nov 15 '22 07:11

Steve Pallen