rails routes command flags
02 Apr 2025TIL about helpful flags built-in to the rails routes task.
-
-g -
allows you to grep the output and filter for any routes that partially match the URL helper method name, the HTTP verb, or the URL path.
Example:rails routes -g new_comment rails routes -g POST rails routes -g admin -
-c -
allows you to filter output by controller name.
Example:rails routes -c users rails routes -c admin/users rails routes -c Posts rails routes -c Devise::Sessions -
--expanded -
makes the output easier to view in smaller terminals.
Example:rails routes --expanded -
--unused -
lists routes that are "unused" in your application. An "unused" route in Rails is a route that is defined in the
config/routes.rbfile but is not referenced by any controller action or view in your application
Example:rails routes --unused