aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-11 00:11:16 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-11 00:11:16 -0600
commit61e9f2023baead046c7f8ba7c89a7496bf49d1be (patch)
tree099d55bc454145e0352c45606c372e846ebad9f6 /actionpack
parent588225f8852c4b60bfba38f16d8797a41e175400 (diff)
downloadrails-61e9f2023baead046c7f8ba7c89a7496bf49d1be.tar.gz
rails-61e9f2023baead046c7f8ba7c89a7496bf49d1be.tar.bz2
rails-61e9f2023baead046c7f8ba7c89a7496bf49d1be.zip
Use rackmounts recognize api and don't piggyback recognize_path on
top of rack call
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb49
2 files changed, 30 insertions, 21 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 3b185c2576..2fa0aab5df 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -2,7 +2,7 @@ module ActionDispatch
module Routing
class Mapper
class Constraints
- def new(app, constraints = [])
+ def self.new(app, constraints = [])
if constraints.any?
super(app, constraints)
else
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index d71ed1d1db..8afd42a293 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -18,36 +18,37 @@ module ActionDispatch
def call(env)
params = env[PARAMETERS_KEY]
+ prepare_params!(params)
+
+ unless controller = controller(params)
+ return [417, {}, []]
+ end
+
+ controller.action(params[:action]).call(env)
+ end
+
+ def prepare_params!(params)
merge_default_action!(params)
split_glob_param!(params) if @glob_param
+
params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
params[key] = URI.unescape(value)
end
end
+ end
- unless controller = controller(params)
- return [417, {}, []]
- end
-
- if env['action_controller.recognize']
- [200, {}, params]
- else
- controller.action(params[:action]).call(env)
+ def controller(params)
+ if params && params.has_key?(:controller)
+ controller = "#{params[:controller].camelize}Controller"
+ ActiveSupport::Inflector.constantize(controller)
end
+ rescue NameError
+ nil
end
private
- def controller(params)
- if params && params.has_key?(:controller)
- controller = "#{params[:controller].camelize}Controller"
- ActiveSupport::Inflector.constantize(controller)
- end
- rescue NameError
- nil
- end
-
def merge_default_action!(params)
params[:action] ||= 'index'
end
@@ -460,6 +461,7 @@ module ActionDispatch
def recognize_path(path, environment = {})
method = (environment[:method] || "GET").to_s.upcase
+ path = Rack::Mount::Utils.normalize_path(path)
begin
env = Rack::MockRequest.env_for(path, {:method => method})
@@ -467,9 +469,16 @@ module ActionDispatch
raise ActionController::RoutingError, e.message
end
- env['action_controller.recognize'] = true
- status, headers, body = call(env)
- body
+ req = Rack::Request.new(env)
+ @set.recognize(req) do |route, params|
+ dispatcher = route.app
+ if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params)
+ dispatcher.prepare_params!(params)
+ return params
+ end
+ end
+
+ raise ActionController::RoutingError, "No route matches #{path.inspect} with #{environment.inspect}"
end
end
end