require "application" desc "Finds unused or obsolete views" task :unused_views => :environment do # First find controllers all_controllers = Dir.glob("#{RAILS_ROOT}/app/controllers/*_controller.rb") all_controllers.each do |controller| controller_file = File.basename(controller, '.rb') controller_short = File.basename(controller, '_controller.rb') require controller_file controller_name = controller_file.camelize controller = controller_name.constantize # Find methods methods = controller.instance_methods - ActionController::Base.instance_methods - ApplicationController.instance_methods # Find views view_files = Dir.glob("#{RAILS_ROOT}/app/views/#{controller_short}/*.rhtml") view_files.map! {|file| File.basename(file,'.rhtml')} view_files.reject! {|file| file =~ /^_/ } view_files.each do |vf| unless methods.include?(vf) puts "Obsolete view #{controller_short}/#{vf}.rhtml" end end end end