A Rake task that helps you find the dead routes and actions for your Rails 3 app
This Rake task investigates your Rails 3 application’s routes definition, then tells you unused routes and unreachable action methods.
-
Ruby 1.8.7, 1.9.2, 1.9.3, 2.0 (trunk)
-
Rails 3.0.x, 3.1.x, 3.2.x, 4.0 (edge)
Put this line in your Gemfile:
gem 'traceroute'
Then bundle:
% bundle
Just run the following command in your Rails app directory.
% rake traceroute
Consider you have the following routes.rb and a controller:
# config/routes.rb YourRailsApp::Application.routes.draw do resources :users, :only => [:index, :show, :new, :create] match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase end # app/controllers/users_controller.rb class UsersController < ApplicationController def index @users = User.page(params[:page]) end def index2 end def show @user = User.find(params[:id]) end end
Running the Rake task will print something like this for you:
Unused routes: users#create users#new catalog#purchase Unreachable action methods: users#index2
OMG super helpful, isn’t it?
Q: It makes a fuss over the default route at the very bottom. WTF? A: Please do not use that. Did you read the comment in your routes.rb? Actually this task will help you a lot to remove that evil route. Q: "command not found: traceroute" Did you mean: tracert A: I'm afraid you're using the wrong operating system.
Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇3☇3☇3
-
Fork, patch, then send me a pull request.
Copyright © 2011 Akira Matsuda. See LICENSE.txt for further details.