From 72160d9f89481ea60c8268ff026099f07b1e5ed6 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sat, 2 May 2009 02:15:09 -0700 Subject: Implement FooController.action(:name) * Rails actions are now Rack endpoints, and can be retrieved via FooController.action(name) and called with an env * Updated some tests that relied on the old internal #process/#call implementation --- actionpack/lib/action_controller/base/base.rb | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'actionpack/lib/action_controller/base/base.rb') diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index 99b5963891..243b7f8ae3 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -370,18 +370,18 @@ module ActionController #:nodoc: attr_reader :template class << self - def call(env) - # HACK: For global rescue to have access to the original request and response - request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env) - response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new - process(request, response) - end - - # Factory for the standard create, process loop where the controller is discarded after processing. - def process(request, response) #:nodoc: - new.process(request, response) + def action(name = nil) + @actions ||= {} + @actions[name] ||= proc do |env| + controller = new + # HACK: For global rescue to have access to the original request and response + request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env) + response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new + controller.action_name = name && name.to_s + controller.process(request, response).to_a + end end - + # Converts the class name from something like "OneModule::TwoModule::NeatController" to "NeatController". def controller_class_name @controller_class_name ||= name.demodulize @@ -518,7 +518,6 @@ module ActionController #:nodoc: assign_shortcuts(request, response) initialize_template_class(response) initialize_current_url - assign_names log_processing send(method, *arguments) @@ -883,10 +882,6 @@ module ActionController #:nodoc: @performed_render || @performed_redirect end - def assign_names - @action_name = (params['action'] || 'index') - end - def reset_variables_added_to_assigns @template.instance_variable_set("@assigns_added", nil) end -- cgit v1.2.3