Forum: Ruby on Rails Controller modules;- Problems if already defined

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.
james.adam (Guest)
on 2005-11-18 18:07
(Received via mailing list)
Rails lets me nest my controllers in modules, so I can happily write:

  class MyModule::MyController < ApplicationController
    ... a file in /app/controllers/my_module/my_controller.rb, and Rails
will load it nicely at http://myapp/my_module/mycontroller.

However, it looks like the dependency mechanism will only work
properly if the MyModule module has not already been defined (by, say,
a plugin). I can understand why Rails might be trying to create the
module for me, so that I wouldn't have to have code like:

  module MyModule
    # empty

...somewhere in my application such that I could then define classes
(controllers) within that module. However, I don't see why Rails
should insist that the module doesn't already exist if I want to put
some controllers in it.

Can anyone comment? Is this a bug, or is this behaviour necessary?

The specific error is:

  Cannot load module MyModule: Object::MyModule is set to MyModule


  routing.rb:236:in `traverse_to_controller'
  generated/routing/recognition.rb:3:in `eval'
  generated/routing/recognition.rb:3:in `recognize_path'


- James
trevor (Guest)
on 2005-11-18 18:43
(Received via mailing list)

I can only assume that it's because the 'MyModule' class is expected to
be a LoadingModule which does automatic loading via const_missing
slightly different from Module.const_missing.

And it might have something to do with being able to discard the loaded
consts when Controllers.clear! is called.

This topic is locked and can not be replied to.