aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/components.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-02-12 05:51:02 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-02-12 05:51:02 +0000
commit050c3964d8fe8d68c03fff593e3c09b5eae77a46 (patch)
tree9331224443d2415be34543af3a94d415c7020d31 /actionpack/lib/action_controller/components.rb
parent838ec413ebe08be71eea3dec0b061c6f609c839f (diff)
downloadrails-050c3964d8fe8d68c03fff593e3c09b5eae77a46.tar.gz
rails-050c3964d8fe8d68c03fff593e3c09b5eae77a46.tar.bz2
rails-050c3964d8fe8d68c03fff593e3c09b5eae77a46.zip
Stopped the massive bleeding of concerns into ActionController::Base. Base no longer knows about flash, filters, or components. This may well have introduced some instability, please do test with apps, especially the ones using components. [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3580 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/components.rb')
-rw-r--r--actionpack/lib/action_controller/components.rb65
1 files changed, 51 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
index 89a2c03aea..28480e47b6 100644
--- a/actionpack/lib/action_controller/components.rb
+++ b/actionpack/lib/action_controller/components.rb
@@ -36,17 +36,36 @@ module ActionController #:nodoc:
# So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.
module Components
def self.included(base) #:nodoc:
+ base.send :include, InstanceMethods
base.extend(ClassMethods)
- base.send(:include, InstanceMethods)
base.helper do
def render_component(options)
@controller.send(:render_component_as_string, options)
end
end
+
+ base.class_eval do
+ alias_method :process_cleanup_without_components, :process_cleanup
+ alias_method :process_cleanup, :process_cleanup_with_components
+
+ alias_method :set_session_options_without_components, :set_session_options
+ alias_method :set_session_options, :set_session_options_with_components
+ end
+
+ # If this controller was instantiated to process a component request,
+ # +parent_controller+ points to the instantiator of this controller.
+ base.send :attr_accessor, :parent_controller
end
module ClassMethods
+ # Track parent controller to identify component requests
+ def process_with_components(request, response, parent_controller = nil) #:nodoc:
+ controller = new
+ controller.parent_controller = parent_controller
+ controller.process(request, response)
+ end
+
# Set the template root to be one directory behind the root dir of the controller. Examples:
# /code/weblog/components/admin/users_controller.rb with Admin::UsersController
# will use /code/weblog/components as template root
@@ -64,6 +83,12 @@ module ActionController #:nodoc:
end
module InstanceMethods
+ # Extracts the action_name from the request parameters and performs that action.
+ def process_with_components(request, response, method = :perform_action, *arguments) #:nodoc:
+ flash.discard if component_request?
+ process_without_components(request, response, method, *arguments)
+ end
+
protected
# Renders the component specified as the response for the current method
def render_component(options) #:doc:
@@ -90,8 +115,8 @@ module ActionController #:nodoc:
klass = component_class(options)
request = request_for_component(klass.controller_name, options)
response = reuse_response ? @response : @response.dup
-
- klass.process(request, response, self)
+
+ klass.process_with_components(request, response, self)
end
# determine the controller class for the component request
@@ -118,18 +143,30 @@ module ActionController #:nodoc:
)
request
- end
+ end
- def component_logging(options)
- if logger
- logger.info "Start rendering component (#{options.inspect}): "
- result = yield
- logger.info "\n\nEnd of component rendering"
- result
- else
- yield
- end
- end
+ def component_logging(options)
+ if logger
+ logger.info "Start rendering component (#{options.inspect}): "
+ result = yield
+ logger.info "\n\nEnd of component rendering"
+ result
+ else
+ yield
+ end
+ end
+
+ def component_request?
+ !@parent_controller.nil?
+ end
+
+ def set_session_options_with_components(request)
+ set_session_options_without_components(request) unless component_request?
+ end
+
+ def process_cleanup_with_components
+ process_cleanup_without_components unless component_request?
+ end
end
end
end