DEV Community

Cover image for Quick Tip: Grepping Rails Routes
SQL Super Hero
SQL Super Hero

Posted on

Quick Tip: Grepping Rails Routes

It is probably safe to say that most Rails developers today are working off either Linux or Mac. However, extensive knowledge of *nix command line tools is not usually required to be a proficient Rails dev. In todays tip, i'll be showing a super simple use case for the grep command to quickly filter the routes output.

As you probably know, rake routes (also rails routes in rails 5) prints a list of all routes in your application - simple enough. As a project grows however, the routes.rb file can get pretty large fairly quickly. This can make finding the actual route you are looking for tough, especially after adding a few engines.

The fix:

rake routes | grep KEYWORD

This will filter the output of the lines to match your keyword.

To return all routes related to a controller, simply add the name of the controller:

rake routes | grep users

To return all routes with a specific HTTP Verb, simply add GET, POST, PATCH:

rake routes | grep GET

To return all routes related to an action:

rake routes | grep update

Super simple, but I find it really useful.

Top comments (0)