Rails 6 shows routes in expanded format

Prathamesh Sonpatki

By Prathamesh Sonpatki

on March 27, 2019

The output of rails routes is in the table format.

1$ rails routes
2   Prefix Verb   URI Pattern               Controller#Action
3    users GET    /users(.:format)          users#index
4          POST   /users(.:format)          users#create
5 new_user GET    /users/new(.:format)      users#new
6edit_user GET    /users/:id/edit(.:format) users#edit
7     user GET    /users/:id(.:format)      users#show
8          PATCH  /users/:id(.:format)      users#update
9          PUT    /users/:id(.:format)      users#update
10          DELETE /users/:id(.:format)      users#destroy

If we have long route names, they don't fit on the terminal window as the output lines wrap with each other.

Example of overlapping routes

Rails 6 has added a way to display the routes in an expanded format.

We can pass --expanded switch to the rails routes command to see this in action.

1$ rails routes --expanded
3--[ Route 1 ]--------------------------------------------------------------
4Prefix            | users
5Verb              | GET
6URI               | /users(.:format)
7Controller#Action | users#index
8--[ Route 2 ]--------------------------------------------------------------
9Prefix            |
10Verb              | POST
11URI               | /users(.:format)
12Controller#Action | users#create
13--[ Route 3 ]--------------------------------------------------------------
14Prefix            | new_user
15Verb              | GET
16URI               | /users/new(.:format)
17Controller#Action | users#new
18--[ Route 4 ]--------------------------------------------------------------
19Prefix            | edit_user
20Verb              | GET
21URI               | /users/:id/edit(.:format)
22Controller#Action | users#edit

This shows the output of the routes command in much more user friendly manner.

The --expanded switch can be used in conjunction with other switches for searching specific routes.