列出所有的控制器以及方法名

阅读更多
controllers = Dir.new("#{RAILS_ROOT}/app/controllers").entries
controllers.each do |controller|
  if controller =~ /_controller/
    control = controller.camelize.gsub(".rb", "")
    puts control
    (eval("#{control}.new.methods") -
        ApplicationController.methods -
        Object.methods -
        ApplicationController.new.methods).sort.each {|method|
      puts "\t#{method}"
    }
  end
end

 

示例输出:

 

EntriesController
        create
        destroy
        update
EntryCommentsController
        create
        destroy
        update

你可能感兴趣的:(ruby,rails,ROR)