aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/components.rb4
-rw-r--r--actionpack/test/controller/components_test.rb26
3 files changed, 31 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index de5c32b033..d400c853c4 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Keep flash after components are rendered. #2291 [Rick Olson, Scott]
+
* Shorten IE file upload path to filename only to match other browsers. #1507 [court3nay@gmail.com]
* Fix open/save dialog in IE not opening files send with send_file/send_data, #2279 [Thomas Fuchs]
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
index 7a6c6139d4..409998525d 100644
--- a/actionpack/lib/action_controller/components.rb
+++ b/actionpack/lib/action_controller/components.rb
@@ -43,7 +43,9 @@ module ActionController #:nodoc:
private
def component_response(options, reuse_response = true)
- component_class(options).process(request_for_component(options), reuse_response ? @response : response_for_component)
+ c = component_class(options)
+ c.after_filter {|c| flash.keep }
+ c.process(request_for_component(options), reuse_response ? @response : response_for_component)
end
def component_class(options)
diff --git a/actionpack/test/controller/components_test.rb b/actionpack/test/controller/components_test.rb
index bf6f246702..b1aa80304c 100644
--- a/actionpack/test/controller/components_test.rb
+++ b/actionpack/test/controller/components_test.rb
@@ -25,6 +25,14 @@ class CallerController < ActionController::Base
render_text "Yes, ma'am"
end
+ def set_flash
+ render_component(:controller => 'callee', :action => 'set_flash')
+ end
+
+ def use_flash
+ render_component(:controller => 'callee', :action => 'use_flash')
+ end
+
def rescue_action(e) raise end
end
@@ -36,6 +44,15 @@ class CalleeController < ActionController::Base
def blowing_up
render_text "It's game over, man, just game over, man!", "500 Internal Server Error"
end
+
+ def set_flash
+ flash[:notice] = 'My stoney baby'
+ render :text => 'flash is set'
+ end
+
+ def use_flash
+ render :text => flash[:notice] || 'no flash'
+ end
def rescue_action(e) raise end
end
@@ -71,4 +88,13 @@ class ComponentsTest < Test::Unit::TestCase
get :internal_caller
assert_equal "Are you there? Yes, ma'am", @response.body
end
+
+ def test_flash
+ get :set_flash
+ assert_equal 'My stoney baby', flash[:notice]
+ get :use_flash
+ assert_equal 'My stoney baby', @response.body
+ get :use_flash
+ assert_equal 'no flash', @response.body
+ end
end \ No newline at end of file