phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.44k stars 2.88k forks source link

Phoenix has gone mad and claims there are no controller modules. #5292

Closed Ilyushya closed 1 year ago

Ilyushya commented 1 year ago

Environment

chrismccord commented 1 year ago

Can you share your entire router file? The double alias prefix of IntellieractiveWeb looks like you have a nested scope in your router? Thanks!

Ilyushya commented 1 year ago

This is a new project, so my router file is almost just regular:

router.ex ``` elixir defmodule Intelliractive23Web.Router do use Intelliractive23Web, :router alias Intelliractive23Web.VideoController alias Intelliractive23Web.PageController import Intelliractive23Web.UserAuth pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_live_flash plug :put_root_layout, {Intelliractive23Web.LayoutView, :root} plug :protect_from_forgery plug :put_secure_browser_headers plug :fetch_current_user end pipeline :api do plug :accepts, ["json"] end scope "/", Intelliractive23Web do pipe_through :browser resources "/vh", VideoController get "/", PageController, :index end # Other scopes may use custom stacks. # scope "/api", Intelliractive23Web do # pipe_through :api # end # Enables LiveDashboard only for development # # If you want to use the LiveDashboard in production, you should put # it behind authentication and allow only admins to access it. # If your application does not have an admins-only section yet, # you can use Plug.BasicAuth to set up some basic authentication # as long as you are also using SSL (which you should anyway). if Mix.env() in [:dev, :test] do import Phoenix.LiveDashboard.Router scope "/" do pipe_through :browser live_dashboard "/dashboard", metrics: Intelliractive23Web.Telemetry end end # Enables the Swoosh mailbox preview in development. # # Note that preview only shows emails that were sent by the same # node running the Phoenix server. if Mix.env() == :dev do scope "/dev" do pipe_through :browser forward "/mailbox", Plug.Swoosh.MailboxPreview end end ## Authentication routes scope "/", Intelliractive23Web do pipe_through [:browser, :redirect_if_user_is_authenticated] get "/users/register", UserRegistrationController, :new post "/users/register", UserRegistrationController, :create get "/users/log_in", UserSessionController, :new post "/users/log_in", UserSessionController, :create get "/users/reset_password", UserResetPasswordController, :new post "/users/reset_password", UserResetPasswordController, :create get "/users/reset_password/:token", UserResetPasswordController, :edit put "/users/reset_password/:token", UserResetPasswordController, :update end scope "/", Intelliractive23Web do pipe_through [:browser, :require_authenticated_user] get "/users/settings", UserSettingsController, :edit put "/users/settings", UserSettingsController, :update get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email end scope "/", Intelliractive23Web do pipe_through [:browser] delete "/users/log_out", UserSessionController, :delete get "/users/confirm", UserConfirmationController, :new post "/users/confirm", UserConfirmationController, :create get "/users/confirm/:token", UserConfirmationController, :edit post "/users/confirm/:token", UserConfirmationController, :update end end ```

I've made some research and realised that a Phoenix project breaks after I transfer files using explorer. There is definetily something wrong with FS changes watcher or live code reloader because it's already the 2nd time I encounter disability to use Phoenix after I import my html (the first time it was saying that there are no such html files)

I do like this and then it's the end:

изображение

chrismccord commented 1 year ago

You need to remove the alias lines in your router. scope "/", MyWeb will already providing the alias prefix to all modules within that scope, so drop the alias and you are good to go!

Ilyushya commented 1 year ago

Thank you! I wonder how they got there

jashanbhoora commented 3 weeks ago

For what it's worth, I've just come into this same issue after having generated a Controller etc. using mix phx.gen.html. Playing things back using undo/redo, it looks like the alias MyAppWeb.MyController was automatically added to my router.ex by VSCode (or rather, the ElixirLS plugin I suppose) when I manually typed/used Intellisense to add resources "/path", MyController to my scope.