Skip to content

Instantly share code, notes, and snippets.

@fabiokr
Created August 15, 2011 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiokr/1147617 to your computer and use it in GitHub Desktop.
Save fabiokr/1147617 to your computer and use it in GitHub Desktop.
Retrieve a list of Rails 3 Controllers (or any other entities)
# Replace "app/controllers" for the kind of thing you are looking for
# A list of available items can be found in rails/railties/lib/rails/engine/configuration.rb#line39
Rails.configuration.paths["app/controllers"].expanded.inject([]) do |controllers, dir|
controllers += Dir["#{dir}/**/*_controller.rb"].map do |file|
file.gsub("#{dir}/", "")
.gsub(".rb", "")
.camelize
.constantize
end
end.uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment