← 返回命令列表

Linux command

rails-routes 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

List all routes

rails routes

Search for routes

rails routes -g [pattern]

Show routes for a specific controller

rails routes -c [controller_name]

Display routes in expanded format

rails routes --expanded

说明

rails routes displays all routes defined in the Rails application. Routes map incoming URLs to controller actions and are defined in config/routes.rb. The output shows the route name (used for URL helpers), HTTP verb, URL pattern, and the controller#action that handles the request. Named routes can be used with _path and _url suffixes in views and controllers. The grep option is useful for large applications with many routes. It searches across all columns, making it easy to find routes by URL pattern, controller name, or route helper name.

参数

-g, --grep _pattern_
Filter routes by pattern (matches against name, verb, path, or controller#action)
-c, --controller _name_
Show routes for a specific controller only
--expanded, -E
Print routes in expanded table format (one attribute per line)
-h, --help
Show help information

FAQ

What is the rails-routes command used for?

rails routes displays all routes defined in the Rails application. Routes map incoming URLs to controller actions and are defined in config/routes.rb. The output shows the route name (used for URL helpers), HTTP verb, URL pattern, and the controller#action that handles the request. Named routes can be used with _path and _url suffixes in views and controllers. The grep option is useful for large applications with many routes. It searches across all columns, making it easy to find routes by URL pattern, controller name, or route helper name.

How do I run a basic rails-routes example?

Run `rails routes` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -g, --grep _pattern_ do in rails-routes?

Filter routes by pattern (matches against name, verb, path, or controller#action)