Rails routes

How To Search Rails Routes

January 17, 2015|Ruby on Rails, Rails, Routes

In a rails application you can easily see what all the routes (or a dynamic way of linking to content in your web application) are available to you. To see what each of the routes available to you are you simply type rake routes into the terminal. You’ll get something like this:

Terminal output for 'rake routes'

This is a very simplified example (a test app that I created to try out some ideas). As your application grows the number of routes will as well. As it grows it takes longer and longer for rake routes to produce all the routes available.

Typically when you’re searching for routes you’re looking for a specific route or group of routes. Maybe, for instance, you are interested only in the user routes - logging in, logging out, signing up, etc. To find just that information you can use a search command “grep” like this: rake routes | grep user and it will show you something like this:

Terminal output for 'rake routes | grep user'

But, what if you wanted everything but users? rake routes | grep -v user

Terminal output for 'rake routes | grep -v user'

Or you can even get more specific and just view routes for a given controller. rake routes CONTROLLER=posts

Terminal output for 'rake routes CONTROLLER=posts'

Learn to Effortlessly Create Anything in CSS

Get access to my free courses, best articles, and tips once a week.

I won't send you spam, promise. If it ever feels that way you can unsubscribe at any time.

Sign Up For Free


Sign In