Tuesday, May 4, 2010

fetch all controllers and actions of the application

dirs = Dir.new("#{RAILS_ROOT}/app/controllers").entries
controller_hash = {}
dirs.each do |controller|
  if controller =~ /_controller/
    path = RAILS_ROOT + '/app/controllers/' + controller
    con = File.read(path).split('def ')
    con.delete_at(0)
    my_hash = Hash.new
    actions = con.collect{|c| c.gsub("\r","~").gsub("\n","~").split("~")[0].strip}
    controller_name = controller.gsub('.rb','')
    my_hash = {controller_name.to_s => actions}
    controller_hash = my_hash.merge(controller_hash)
  end
end
puts controller_hash.inspect

Contact Me for any help regarding rails/nodejs/php/mysql

Name

Email *

Message *