aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-05-02 02:15:09 -0700
committerYehuda Katz <wycats@gmail.com>2009-05-02 02:15:09 -0700
commit72160d9f89481ea60c8268ff026099f07b1e5ed6 (patch)
tree950b7516323658c7012e3ca742b7bd9930a83aa7 /actionpack/lib
parentad2a1b5cb1afb0ea810cfdcac2ba1be95c55f1aa (diff)
downloadrails-72160d9f89481ea60c8268ff026099f07b1e5ed6.tar.gz
rails-72160d9f89481ea60c8268ff026099f07b1e5ed6.tar.bz2
rails-72160d9f89481ea60c8268ff026099f07b1e5ed6.zip
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
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/base/base.rb27
-rw-r--r--actionpack/lib/action_controller/new_base/http.rb13
-rw-r--r--actionpack/lib/action_controller/routing/route_set.rb2
-rw-r--r--actionpack/lib/action_controller/testing/process.rb4
4 files changed, 26 insertions, 20 deletions
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
diff --git a/actionpack/lib/action_controller/new_base/http.rb b/actionpack/lib/action_controller/new_base/http.rb
index f663900944..b7e3bfaa7e 100644
--- a/actionpack/lib/action_controller/new_base/http.rb
+++ b/actionpack/lib/action_controller/new_base/http.rb
@@ -39,13 +39,20 @@ module ActionController
end
# :api: private
- def call(env)
+ def call(name, env)
@_request = ActionDispatch::Request.new(env)
@_response = ActionDispatch::Response.new
- process(@_request.parameters[:action])
+ process(name)
@_response.body = response_body
@_response.prepare!
- self
+ to_rack
+ end
+
+ def self.action(name)
+ @actions ||= {}
+ @actions[name] ||= proc do |env|
+ new.call(name, env)
+ end
end
# :api: private
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index 70cd1f642d..45ad8a3a3b 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -430,7 +430,7 @@ module ActionController
def call(env)
request = ActionDispatch::Request.new(env)
app = Routing::Routes.recognize(request)
- app.call(env).to_a
+ app.action(request.parameters[:action] || 'index').call(env)
end
def recognize(request)
diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb
index 8315a160ad..3aad94cc10 100644
--- a/actionpack/lib/action_controller/testing/process.rb
+++ b/actionpack/lib/action_controller/testing/process.rb
@@ -131,7 +131,11 @@ module ActionController #:nodoc:
@request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
build_request_uri(action, parameters)
+ @request.env["action_controller.rescue.request"] = @request
+ @request.env["action_controller.rescue.request"] = @response
+
Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest
+ @controller.action_name = action.to_s
@controller.process(@request, @response)
end