From 8e7a87d299483fce6af3be89e50deae43055a96f Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 21 May 2009 01:38:48 +0200 Subject: Make ActionController::Flash work with new_base --- .../lib/action_controller/base/chained/flash.rb | 74 +++++++++++++++------- 1 file changed, 52 insertions(+), 22 deletions(-) (limited to 'actionpack/lib/action_controller/base/chained/flash.rb') diff --git a/actionpack/lib/action_controller/base/chained/flash.rb b/actionpack/lib/action_controller/base/chained/flash.rb index 56ee9c67e2..6bd482d85a 100644 --- a/actionpack/lib/action_controller/base/chained/flash.rb +++ b/actionpack/lib/action_controller/base/chained/flash.rb @@ -26,9 +26,18 @@ module ActionController #:nodoc: # # See docs on the FlashHash class for more details about the flash. module Flash - def self.included(base) - base.class_eval do - include InstanceMethods + extend ActiveSupport::DependencyModule + + # TODO : Remove the defined? check when new base is the main base + depends_on Session if defined?(ActionController::Http) + + included do + # TODO : Remove the defined? check when new base is the main base + if defined?(ActionController::Http) + include InstanceMethodsForNewBase + else + include InstanceMethodsForBase + alias_method_chain :perform_action, :flash alias_method_chain :reset_session, :flash end @@ -135,29 +144,50 @@ module ActionController #:nodoc: end end - module InstanceMethods #:nodoc: + module InstanceMethodsForBase #:nodoc: protected - def perform_action_with_flash - perform_action_without_flash - remove_instance_variable(:@_flash) if defined? @_flash - end - def reset_session_with_flash - reset_session_without_flash - remove_instance_variable(:@_flash) if defined? @_flash - end + def perform_action_with_flash + perform_action_without_flash + remove_instance_variable(:@_flash) if defined?(@_flash) + end - # Access the contents of the flash. Use flash["notice"] to - # read a notice you put there or flash["notice"] = "hello" - # to put a new one. - def flash #:doc: - unless defined? @_flash - @_flash = session["flash"] ||= FlashHash.new - @_flash.sweep - end + def reset_session_with_flash + reset_session_without_flash + remove_instance_variable(:@_flash) if defined?(@_flash) + end + end - @_flash - end + module InstanceMethodsForNewBase #:nodoc: + protected + + def reset_session + super + remove_flash_instance_variable + end + + def process_action(method_name) + super + remove_flash_instance_variable + end + + def remove_flash_instance_variable + remove_instance_variable(:@_flash) if defined?(@_flash) + end + end + + protected + + # Access the contents of the flash. Use flash["notice"] to + # read a notice you put there or flash["notice"] = "hello" + # to put a new one. + def flash #:doc: + unless defined?(@_flash) + @_flash = session["flash"] ||= FlashHash.new + @_flash.sweep + end + + @_flash end end end -- cgit v1.2.3