After a few years of continuous development, your becomes larger and it’s good practice to do some cleanup. One of the most obvious cleanups is cleaning up unused routes. rails application As your rails application grows, at the time of adding a route for new action, developers sometimes add in file rather than adding a single member or collection route which creates unnecessary routes at runtime 😖 resources :objects config/routes.rb For example, Rails.application.routes.draw resources do :users end Writing above code will create the following routes - But, it might be possible that we are not using all of the above methods, or we need only , and methods in our Users controller like - users#new users#create users#show < ApplicationController class UsersController def new end def create end def show end end So, it’s the most obvious process to inspect your file from time to time and clean it if necessary. routes.rb Inspecting each route and its corresponding action took so much time and it’s next to impossible thing when the application is so large 😞 Now, there are few available in the market which can do it for you, but again adding additional gem requires extra load in your gemfile of your large application. ruby gems Another solution is to make a simple script which compares routes and associated actions available in controllers and list down all possible unused routes of our large application so that we can clean file and remove routes that are not needed. routes.rb Have a look at following a small ruby script - Rails.application.eager_load! unused_routes = {} Rails.application.routes.routes.map(& ).reject(& ).each name = route[ ].camelcase name.start_with?( ) controller = Object.const_defined?(controller) && !controller.constantize.new.respond_to?(route[ ]) Dir.glob(Rails.root.join( , , name.downcase, )).any? unused_routes[controller] = [] unused_routes[controller]. ? unused_routes[controller] << route[ ] puts unused_routes # Iterating over all non-empty routes from RouteSet :requirements :empty? do |route| :controller next if "Rails" " Controller" #{name} if :action # Get route for which associated action is not present and add it in final results unless "app" "views" " .*" #{route[ ]} :action if nil :action end end end # {"UsersController"=>["edit", "update", "update", "destroy"]} For getting unused routes for your rails app, all you need to do is to copy above code in your or you can paste above code in single file in the root directory of your Rails application and run it using the following command - rails console get-unused-routes.rb $> ruby get-unused-routes.rb Using above small script we’re able to get all unused routes of our large rails application, we don’t use any Gem/Plugin to achieve this 🥳 References - Rails Routing from the Outside in RouteSet A deep dive into Routing & Controller Dispatch in Rails TraceRoute Reference to my Gists Found this post useful? please share to help others find it! Feel free to leave a comment below.