How to use routes in Ruby on Rails like a pro
TIL (Today I Learned) that in Rails, you can filter routes by a specific controller or namespace using the
rails routes
command with the -c
option.For instance, if you want to filter routes by a specific controller, like UsersController, you can run:
rails routes -c UsersController
This command will display only the routes that are handled by the UsersController.
But hey, if you need to narrow it down even further by a specific namespace, Rails got your back! Just add the namespace followed by a double colon (::) after the
-c
option. For example, if your controller is within the Users namespace, you can use:rails routes -c Users::
And voila! You'll see only the routes associated with the Users namespace. Handy, right? Now you can navigate through your routes like a boss! 🚀
Discover More Reads
Categories: