Quick Hack: List all of Your Rails Controllers and Models

Posted on August 31, 2007

Let’s say you’re working on a small team and need to divvy up your models and controllers to do a code sweep.

You want to place these in a Google Docs spreadsheet or something. The code:

files = []
Dir["app/controllers/*"].each do |f|
 f = f.gsub('app/controllers/', '')
 files << f
end

Dir["app/models/*"].each do |f|
 f = f.gsub('app/models/', '')
 files << f
end

files.each do |f|
  puts f
end

Note: does not handle nested subdirectories within your app/models/ or app/controllers/ directories.