do you want to operate on the class/module constant or the url path? how about controller.class.to_s.split('::') # pop off the last one if you just want its parents ?
On Thu, Mar 19, 2009 at 1:23 PM, John Barton <jrbar...@gmail.com> wrote: > > We sometimes use > > controller.controller_path.split('/')[0] > > to determine if we're in a namespaced subdir (usually for setting nav > bar stuff up) > > -jb > > On Mar 18, 1:56 pm, Clifford Heath <clifford.he...@gmail.com> wrote: > > On 18/03/2009, at 1:51 PM, Mark Ratjens wrote: > > > > > I'm in the midst of refactoring some code and I want to be able to > > > generically discover the module of a given controller (essentially > > > so I > > > can dynamically build named routes rather than have them hard-coded > > > into > > > each controller). > > > > Facets has Module.modspace, defined: > > > > class Module > > def modspace > > space = name[ 0...(name.rindex( '::' ) || 0)] > > space == '' ? Object : eval(space) > > end > > end > > > > Clifford Heath. > > > -- cheers, David Lee --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to rails-oceania@googlegroups.com To unsubscribe from this group, send email to rails-oceania+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en -~----------~----~----~----~------~----~------~--~---