Skip to content

Instantly share code, notes, and snippets.

@secretpray
Last active March 12, 2022 10:14
Show Gist options
  • Save secretpray/9eb5ebc779de3c70637152bf165a0729 to your computer and use it in GitHub Desktop.
Save secretpray/9eb5ebc779de3c70637152bf165a0729 to your computer and use it in GitHub Desktop.
Search in rails routes

Searching with Browser

You will have four outputs for each route. These outputs are the route name (if it exists), the HTTP verb, the url pattern and the routing parameters (if they are used). These four pieces of information are very useful in determining the full route including namespaces, what the components of the URI are, the action that will be performed when the endpoint is hit and what kind of parameters can be expected.

https://localhost:3000/rails/info/routes

Searching with Grep

Developers who are already familiar with linux or bash may know the grep command, which makes searching for items by text easier. The grep command stands for global regular expression print and allows users to search for items matching parts of an input string.

rails routes | grep <search_name>

Searching with Grep pattern

rails routes -g <search_name>

Searching Based on Controllers

Another way to limit your search results is to search by controller. With the Rails MVC architecture, it makes sense to look at actions as a collection of methods of a controller. Therefore, seeing the paths for each controller action is helpful.

rails routes -c <controller_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment