DEV Community

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

Posted on

1

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay