Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created September 3, 2014 18:26
Show Gist options
  • Save tiegz/1ce5b2ae4f4f2e9efefd to your computer and use it in GitHub Desktop.
Save tiegz/1ce5b2ae4f4f2e9efefd to your computer and use it in GitHub Desktop.
Find unused rails routes
# There could likely be some false positives from this
Rails.application.routes.routes.select do |r|
name = r.defaults[:controller].to_s.classify + "Controller"
klass = name.constantize rescue nil
if klass.nil?
name = r.defaults[:controller].to_s.classify.pluralize + "Controller"
klass = name.constantize rescue nil
end
klass.nil? || !klass.action_methods.include?(r.defaults[:action])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment