views:

266

answers:

3

I'm trying to build a RESTful app to actually manage many kind of configurable objects, so there are a large amount of "resource" types, and hence a lot of controllers. I'm still at the POC phase, so it will be nice if I can show all controllers in a first navigation page, so any easy way (programmable) to do that?

A: 

You could certainly list the files in the controllers directory.

toby
+1  A: 

Google: 'rails list controllers'

First result.

http://snippets.dzone.com/posts/show/4792


After learning about the subclasses, I think the code from my link could be done simply as..

ApplicationController.subclasses.each do |c|
  puts "Controller: #{c}"
  puts "Actions: #{c.constantize.action_methods.collect{|a| a.to_s}.join(', ')}"
end
Jim
If you're going to list controllers and actions, why not just use rake routes? Sure the output is messy, but that's fixed by expanding your terminal window.
EmFi
I just was putting down quick code that would be similar to what the link was doing. Practicing a bit so I remember.
Jim
+4  A: 
ApplicationController.subclasses

It'll get you started, but keep in mind that in development mode you won't see much, because it will only show you what's actually been loaded. Fire it up in production mode, and you should see a list of all of your controllers.

jdl
You can require all files in "#{RAILS_ROOT}/app/controllers" to populate your list in development mode.
EmFi
Cool. Learned something new. I guess running around this site is doing me some good.
Jim