Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix controller resolution to avoid accidentally inheriting a controll…
…er from a parent module.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3530 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
seckar committed Feb 4, 2006
1 parent c77729f commit dfa6e14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion actionpack/CHANGELOG
@@ -1,6 +1,8 @@
*SVN* *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] * Subclasses of ActionController::Caching::Sweeper should be Reloadable. [Rick Olson]


Expand Down
8 changes: 6 additions & 2 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -233,15 +233,19 @@ def traverse_to_controller(segments, start_at = 0)
controller_name = "#{mod_name}Controller" controller_name = "#{mod_name}Controller"


suppress(NameError) do 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. # 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}" if mod == Object || controller.name == "#{mod.name}::#{controller_name}"
return controller, (index - start_at) return controller, (index - start_at)
end end
end end


mod = suppress(NameError) do 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 # Check that we didn't get a module from a parent namespace
(mod == Object || next_mod.name == "#{mod.name}::#{controller_name}") ? next_mod : nil (mod == Object || next_mod.name == "#{mod.name}::#{controller_name}") ? next_mod : nil
end end
Expand Down

0 comments on commit dfa6e14

Please sign in to comment.