diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 7c00e8d8dd..f61908a820 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,6 +1,8 @@ *SVN* -* Set sweeper's @controller to nil after a request so that the controller may be collected between requests. +* Fix controller resolution to avoid accidentally inheriting a controller from a parent module. [Nicholas Seckar] + +* Set sweeper's @controller to nil after a request so that the controller may be collected between requests. [Nicholas Seckar] * Subclasses of ActionController::Caching::Sweeper should be Reloadable. [Rick Olson] diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 7693cd0711..fe0d7be541 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -233,15 +233,19 @@ module ActionController controller_name = "#{mod_name}Controller" suppress(NameError) do - controller = mod.const_get(controller_name) + ActionController::Base.logger.info("Looking for #{controller_name}") + controller = eval("mod::#{controller_name}", nil, __FILE__, __LINE__) + ActionController::Base.logger.info("Found") # Detect the case when const_get returns an object from a parent namespace. + + ActionController::Base.logger.info("#{controller.name} == #{mod.name}::#{controller_name}") if mod == Object || controller.name == "#{mod.name}::#{controller_name}" return controller, (index - start_at) end end mod = suppress(NameError) do - next_mod = mod.const_get(mod_name) + next_mod = eval("mod::#{mod_name}", nil, __FILE__, __LINE__) # Check that we didn't get a module from a parent namespace (mod == Object || next_mod.name == "#{mod.name}::#{controller_name}") ? next_mod : nil end