Showing routes

mix phx.routes        # 1.3+
mix phoenix.routes    # 1.2 and below

See: Mix.Tasks.Phoenix.Routes (

Single routes

get "/", PageController, :index

Also: put post patch options delete head


resources "/users", UserController
resources "/users", UserController, only: [:index, :show]
resources "/users", UserController, except: [:delete]
resources "/users", UserController,
  as: :person    # helper name (person_path)
  name: :person  # ...?
  param: :id     # name of parameter for this resource

Generates these routes:

Method Path Helper
GET /users user_path(:index)
GET /users/new user_path(:new)
GET /users/:id user_path(:show, user)
GET /users/:id/edit user_path(:edit, user)
POST /users user_path(:create, user)
PATCH/PUT /users/:id user_path(:update, user)
DELETE /users/:id user_path(:delete, user)

See: resources/4 (

Path helpers

user_path(conn, :index)                 # → /users
user_path(conn, :show, 17)              # → /users/17
user_path(conn, :show, %User{id: 17})   # → /users/17
user_path(conn, :show, 17, admin: true) # → /users/17?admin=true
user_url(conn, :index) # → "http://localhost:4000/users"
MyApp.Router.Helpers.user_path(MyApp.Endpoint, :index)

See: Helpers (

Nested resources

resources "/users", UserController do
  resources "/posts", PostController
user_post_path(:index, 17)     # → /users/17/posts
user_post_path(:show, 17, 12)  # → /users/17/posts/12

See: Scopes and resources (

Scoped routes

scope "/admin" do
  pipe_through :browser
  resources "/reviews", MyApp.Admin.ReviewController
# reviews_path() -> /admin/reviews
scope "/admin", as: :admin do: ... end
# admin_reviews_path() -> /admin/reviews

See: scope/2 (

0 Comments for this cheatsheet. Write yours!