Forum: Ruby on Rails Getting the module name with ObjectSpace...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-03-21 13:58
(Received via mailing list)
Hey :)

I'm trying to create a method for making a sitemap dynamically. It
works great for flat sites where you simply have your controllers in
the app/controllers directory. In this case, I can extract the
controller names like,

  ObjectSpace.subclasses_of(ActionController::Base).each do |obj|
      @controllers["#{obj.controller_name}"] = obj

However, now I've divided the site into modules, that is, I have for
instance both Store::ItemsController and Manage::ItemsController,
which reside in app/controllers/store and app/controllers/manage

This causes my code above to basically (as it seems) discard the
"duplicate" controllers when traversing the classes. What I'd like to
do is mimic the hierarchy in my module::controller::action structure,
but I don't know how to do that...

I'd like to have a three dimensional array like, [module_name]


Thanks :)

This topic is locked and can not be replied to.