Made the sharing of request and response safer

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 752f9ab8
module ActionController #:nodoc: module ActionController #:nodoc:
# TODO: Cookies and session variables set in render_component that happens inside a view should be copied over.
module Components #:nodoc: module Components #:nodoc:
def self.append_features(base) def self.append_features(base)
super super
...@@ -14,16 +15,16 @@ def render_component(options) ...@@ -14,16 +15,16 @@ def render_component(options)
protected protected
def render_component(options = {}) #:doc: def render_component(options = {}) #:doc:
response = component_response(options) response = component_response(options, true)
logger.info "Rendering component (#{options.inspect}): " logger.info "Start rendering component (#{options.inspect}): "
result = render_text(response.body, response.headers["Status"]) result = render_text(response.body, response.headers["Status"])
logger.info("\n\nEnd of component rendering") logger.info("\n\nEnd of component rendering")
return result return result
end end
private private
def component_response(options) def component_response(options, reuse_response = false)
component_class(options).process(component_request(options), @response) component_class(options).process(component_request(options), reuse_response ? @response : component_response)
end end
def component_class(options) def component_class(options)
...@@ -31,12 +32,16 @@ def component_class(options) ...@@ -31,12 +32,16 @@ def component_class(options)
end end
def component_request(options) def component_request(options)
component_request = @request.dup component_request = Marshal::load(Marshal::dump(@request))
component_request.send( component_request.send(
:instance_variable_set, :@parameters, :instance_variable_set, :@parameters,
(options[:params] || {}).merge({ "controller" => options[:controller], "action" => options[:action] }) (options[:params] || {}).merge({ "controller" => options[:controller], "action" => options[:action] })
) )
return component_request return component_request
end end
def component_response
Marshal::load(Marshal::dump(@response))
end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册