I’m building a blog where I want anyone coming to my website to be able to see all posts and also the specific page of each post (so
show routes). But I want only users with
is_admin: true to be able to create, edit or delete post.
Hence, here is what I did:
[...] pipeline :admin_required do plug Gazette.CheckAdmin end scope "/", GazetteWeb do pipe_through [:browser, :with_session] get "/", PageController, :index resources "/users", UserController, only: [:show, :new, :create] resources "/sessions", SessionController, only: [:new, :create, :delete] resources "/posts", PostController, only: [:index, :show] end scope "/posts", GazetteWeb do pipe_through [:admin_required] resources "/", PostController, except: [:index, :show] end [...]
my problem is, when I go to /posts/new, Phoenix believes I make a request to the show route (/posts/:id) where id is “new”. In another word it goes to the wrong pipeline.
How can I solve that ?