-
-
Save rishiip/b3f87d0b410dde7f717ce328e2dada73 to your computer and use it in GitHub Desktop.
Gists for - Get unused routes of your Rails App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.eager_load! | |
unused_routes = {} | |
# Iterating over all non-empty routes from RouteSet | |
Rails.application.routes.routes.map(&:requirements).reject(&:empty?).each do |route| | |
name = route[:controller].camelcase | |
next if name.start_with?("Rails") | |
controller = "#{name}Controller" | |
if Object.const_defined?(controller) && !controller.constantize.new.respond_to?(route[:action]) | |
# Get route for which associated action is not present and add it in final results | |
unless Dir.glob(Rails.root.join("app", "views", name.downcase, "#{route[:action]}.*")).any? | |
unused_routes[controller] = [] if unused_routes[controller].nil? | |
unused_routes[controller] << route[:action] | |
end | |
end | |
end | |
puts unused_routes | |
# {"HomeController"=>["edit", "update", "update", "destroy"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
resources :users | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTP Verb | Path | Controller#Action | Used for | |
---|---|---|---|---|
GET | /users | users#index | Display a list of all users | |
GET | /users/new | users#new | Return an HTML form for creating a new user | |
POST | /users | users#create | Create a new user | |
GET | /users/:id | users#show | Display a specific user | |
GET | /users/:id/edit | users#edit | Return an HTML form for editing a user | |
PATCH/PUT | /users/:id | users#update | Update a specific user | |
DELETE | /users/:id | users#destroy | Delete a specific user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def new | |
end | |
def create | |
end | |
def show | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment