How To Search Rails Routes

If you have a big Rails application, it might take a while to run the standard rake routes command in your Terminal. Plus, once you run “rake routes”, you have to look through all of them to find the ones for only the model you need.

So let’s say you only want to know which routes have a “/user” in them. Simply type rake routes | grep user in your Terminal. If you’re using devise with your user model, you’ll only get the following search results:

The “grep” command is the standard way to run a search in the Terminal. Combining it with rake routes makes it easy to see only the routes you want.

Enjoy the article? Join over 14,500+ Swift developers and enthusiasts who get my weekly updates.

  • Malik

    And
    rake routes | grep -v user
    will return the inverse of the above result, routes those don’t have word user.

  • zlarsen

    This is awesome! It really helped me out on my website zachariahlarsen.com

  • funkdified

    Hey thanks for pointing this out. Very helpful. Another win for grep!