When looking at upcoming major releases of projects like Ruby on Rails, it can be easy to get distracted by the big, flashy features, such as Hotwire and encrypted attributes in Rails 7.0. However, sometimes I find myself getting more excited by smaller, more modest additions in upcoming releases. This is the case with the recent merge of a PR to Rails that will form part of Rails 7.1: Add routes --unused option to detect extraneous routes by Gannon McGibbon.
We all know the rails routes
command which lists all the routes in your app, detailing their name, HTTP method, path, controller and action. But in a large app with lots of routes that might have seen a rewrite or two or a few years of churn, how do you know which routes are still valid (where "valid" means the controller and action that the route points to exists)?
Introducing the new --unused
option (full command: rails routes --unused
).
From an implementation point-o