aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/components.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/components.rb')
-rw-r--r--actionpack/lib/action_controller/components.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
new file mode 100644
index 0000000000..681c7b6d9a
--- /dev/null
+++ b/actionpack/lib/action_controller/components.rb
@@ -0,0 +1,29 @@
+module ActionController #:nodoc:
+ module Components #:nodoc:
+ def self.append_features(base)
+ super
+ base.helper { def render_component(options) @controller.send(:component_response, options).body end }
+ end
+
+ protected
+ def render_component(options = {}) #:doc:
+ response = component_response(options)
+ render_text(response.body, response.response_code)
+ end
+
+ private
+ def component_response(options)
+ component_class(options).process(component_request(options), @response)
+ end
+
+ def component_class(options)
+ options[:controller] ? (options[:controller].camelize + "Controller").constantize : self
+ end
+
+ def component_request(options)
+ component_request = @request.dup
+ component_request.send(:instance_variable_set, :@parameters, options[:params].merge({ "controller" => options[:controller], "action" => options[:action] }))
+ component_request
+ end
+ end
+end