In my Rails app I have an AdminController in app/controllers/admin
:
module Admin
class AdminController < ApplicationController
end
end
And then inside the admin folder I have various other controllers which all inherit from the AdminController, e.g.
module Admin
class PermissionsController < AdminController
end
end
I'm trying to list all the controllers and actions under AdminController with:
def list
@controllers = AdminController.descendants
end
But all I get is: Admin::PermissionsController
I've also tried AdminController.subclasses
but get the same.
I don't want to do @controllers = Dir.new("#{Rails.root}/app/controllers/admin").entries
because I also want to access the action_methods
.
Why isn't descendants
or subclasses
working?
In my view I want to do:
<% @controllers.each do |controller| %>
<h2><%= controller %></h2>
<ul>
<% controller.action_methods.each do |action| %>
<li><%= action %></li>
<% end %>
</ul>
<% end %>
Which does list all the actions but only for the current controller and it also lists action methods from the parent controllers. I only want to list the ones for each controller.