aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-11-23 20:20:50 -0600
committerJoshua Peek <josh@joshpeek.com>2009-11-23 20:20:50 -0600
commit15ab3a98a1b6f9b829060ba974048b33466f6814 (patch)
tree17ffc94d9ddb1144e8367ccda2e3fd17d238bf8b /actionpack/lib
parentf987e8561c2fdbf5f6ade34d68f66b6e7e19d8d3 (diff)
downloadrails-15ab3a98a1b6f9b829060ba974048b33466f6814.tar.gz
rails-15ab3a98a1b6f9b829060ba974048b33466f6814.tar.bz2
rails-15ab3a98a1b6f9b829060ba974048b33466f6814.zip
Find all controllers in memory to use for routing
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing.rb19
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb4
2 files changed, 15 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb
index 4bb7713c98..b43b77fecb 100644
--- a/actionpack/lib/action_dispatch/routing.rb
+++ b/actionpack/lib/action_dispatch/routing.rb
@@ -280,6 +280,10 @@ module ActionDispatch
Regexp.union(*possible_controllers.collect { |n| Regexp.escape(n) })
end
+ def clear_controller_cache!
+ @possible_controllers = nil
+ end
+
# Returns an array of paths, cleaned of double-slashes and relative path references.
# * "\\\" and "//" become "\\" or "/".
# * "/foo/bar/../config" becomes "/foo/config".
@@ -307,8 +311,15 @@ module ActionDispatch
unless @possible_controllers
@possible_controllers = []
- paths = controller_paths.select { |path| File.directory?(path) && path != "." }
+ # Find any controller classes already in memory
+ ActionController::Base.subclasses.each do |klass|
+ controller_name = klass.underscore
+ controller_name.gsub!(/_controller\Z/, '')
+ @possible_controllers << controller_name
+ end
+ # Find controllers in controllers/ directory
+ paths = controller_paths.select { |path| File.directory?(path) && path != "." }
seen_paths = Hash.new {|h, k| h[k] = true; false}
normalize_paths(paths).each do |load_path|
Dir["#{load_path}/**/*_controller.rb"].collect do |path|
@@ -326,12 +337,6 @@ module ActionDispatch
end
@possible_controllers
end
-
- # Replaces the internal list of controllers available to ActionController::Routing with the passed argument.
- # ActionController::Routing.use_controllers!([ "posts", "comments", "admin/comments" ])
- def use_controllers!(controller_names)
- @possible_controllers = controller_names
- end
end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index c15aaceb5b..79e15edeaa 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -246,7 +246,9 @@ module ActionDispatch
end
def load!
- Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
+ # Clear the controller cache so we may discover new ones
+ Routing.clear_controller_cache!
+
load_routes!
end