How to get list of controllers and actions in ruby on rails?

前端 未结 4 740
你的背包
你的背包 2020-12-07 20:50

In rails, I can get the name of the current controller via controller_name and the current action by calling action_name. I am looking for similar runtime reflection for fet

4条回答
  •  旧时难觅i
    2020-12-07 21:24

    We are cleaning out unused controllers and actions. So I wanted to create an exhaustive list to mark for deletion. Here's what I ended up doing

    ApplicationController.descendants.each do |controller|
      puts controller.name
      controller.action_methods.each do |action|
        puts '  ' + action
      end
    end
    

    That provides a nice list with actions indented under controller names.

提交回复
热议问题