View Source Routing cheatsheet

Those need to be declared in the correct router module and scope.

A quick reference to the common routing features' syntax. For an exhaustive overview, refer to the routing guides.

Routing declaration

Single route

get "/users", UserController, :index
patch "/users/:id", UserController, :update
# generated routes
~p"/users"
~p"/users/9" # user_id is 9

Also accepts put, patch, options, delete and head.

Resources

Simple

resources "/users", UserController

Generates :index, :edit, :new, :show, :create, :update and :delete.

Options

resources "/users", UserController, only: [:show]
resources "/users", UserController, except: [:create, :delete]
resources "/users", UserController, as: :person # ~p"/person"

Nested

resources "/users", UserController do
  resources "/posts", PostController
end
# generated routes
~p"/users/3/posts" # user_id is 3
~p"/users/3/posts/17" # user_id is 3 and post_id = 17

For more info check the resources docs.

Scopes

Simple

scope "/admin", HelloWeb.Admin do
  pipe_through :browser

  resources "/users",   UserController
end
# generated path helpers
~p"/admin/users"

Nested

scope "/api", HelloWeb.Api, as: :api do
  pipe_through :api

  scope "/v1", V1, as: :v1 do
    resources "/users", UserController
  end
end
# generated path helpers
~p"/api/v1/users"

For more info check the scoped routes docs.