0
私のアプリケーションは動作し、api jsonリクエストと通常のhtmlがあります。マイrouter.exphoenix viewモジュールが利用できません
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
私のWeb /コントローラ/ 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
と私のWeb /コントローラ/ 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
私のWeb /ビュー/ V1 /user_view.ex
defmodule MyApp.V1.UserView do
use MyApp.Web, :view
...
end
と私のweb/views/u ser_view.ex
defmodule MyApp.UserView do
use MyApp.Web, :view
end
html用のルートとコントローラを追加するまではすべて正常に機能します。私は、APIのJSONを要求するとき は今、私はエラー
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)
を取得しかし、私はウェブ/ vews/user_view.exを削除する場合は、このクエリはエラーなしで動作します。 このエラーを修正するにはどうすればよいですか?
これらのエラーは、コンパイルの問題が発生し、アプリケーションを再起動しなかった場合に表示されることがあります。 phoenixサーバーからdouble crtl-cを試してみてください。また 'ミックスクリーン'を実行して、フェニックスサーバを再起動してみてください。私が考えることができる唯一の別のものはエイリアスの問題です。 UserViewモジュールの名前を一時的に変更して、それが役立つかどうかを確認できます。 –
@StevePallenはい、たとえばUserViewHtmlのMyApp.UserViewの名前を変更すると問題が解決します。しかし、私は別の解決策があることを望んでいた。 –
おそらく、コンパイル/ロードに関する問題がある。また、HTMLモジュールにCode.ensure_loaded/1を追加することもできます。 –